Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2018-08-31 06:58:10 -0400
committerHenrik Rentz-Reichert2018-08-31 11:43:54 -0400
commit939c36bfa9fda11e14101a3552400f0137ced60c (patch)
tree1da3417d95ab3d0c9239542ba0b1477e51485434
parent4176da47b063d5e93bd0d9c149391dde97966263 (diff)
downloadorg.eclipse.etrice-939c36bfa9fda11e14101a3552400f0137ced60c.tar.gz
org.eclipse.etrice-939c36bfa9fda11e14101a3552400f0137ced60c.tar.xz
org.eclipse.etrice-939c36bfa9fda11e14101a3552400f0137ced60c.zip
Bug 538485 [runtime.java] Fix race condition in message servicev_2.0.0.M1
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageSeQueue.java6
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java37
2 files changed, 23 insertions, 20 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageSeQueue.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageSeQueue.java
index 4496dd928..d33c4a63a 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageSeQueue.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageSeQueue.java
@@ -74,8 +74,12 @@ public class MessageSeQueue extends RTObject{
return last;
}
+ public boolean isEmpty() {
+ return last == null;
+ }
+
public boolean isNotEmpty(){
- return last != null;
+ return !isEmpty();
}
public long getHightWaterMark() {
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java
index 84a9bf98c..d8b5b58e1 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java
@@ -70,34 +70,33 @@ public class MessageService extends AbstractMessageService {
public void run() {
running = true;
- if(pollingScheduler != null)
+ if(pollingScheduler != null) {
pollingScheduler.scheduleAtFixedRate(new PollingTask(), pollingInterval, pollingInterval, TimeUnit.NANOSECONDS);
+ }
- while (running) {
+ while(true) {
Message msg = null;
-
- // get next Message from Queue
+
synchronized(this) {
- msg = getMessageQueue().pop();
- }
-
- if (msg == null) {
- // no message in queue -> wait until Thread is notified
- try {
- synchronized(this) {
- if (!running)
- return;
+ while(getMessageQueue().isEmpty() && running) {
+ // no message in queue -> wait until Thread is notified
+ try {
wait();
}
+ catch (InterruptedException e) {}
}
- catch (InterruptedException e) {
+ if(!running) {
+ return;
+ }
+ else {
+ // get next Message from Queue
+ msg = getMessageQueue().pop();
}
}
- else {
- // process message
- lastMessageTimestamp = System.currentTimeMillis();
- getMessageDispatcher().receive(msg);
- }
+
+ // process message
+ lastMessageTimestamp = System.currentTimeMillis();
+ getMessageDispatcher().receive(msg);
}
}

Back to the top