Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2013-08-12 12:00:46 -0400
committerHenrik Rentz-Reichert2013-08-12 12:00:46 -0400
commit32037f336c01f16526bc3918dd55590ba9513fc7 (patch)
treed410848eefeff5b3b63d08b2375682d24f8296ba /runtime/org.eclipse.etrice.runtime.java/src/org/eclipse
parent8ea61c85f6c14de12f1be0da43dbf188097a14f8 (diff)
downloadorg.eclipse.etrice-32037f336c01f16526bc3918dd55590ba9513fc7.tar.gz
org.eclipse.etrice-32037f336c01f16526bc3918dd55590ba9513fc7.tar.xz
org.eclipse.etrice-32037f336c01f16526bc3918dd55590ba9513fc7.zip
[runtime.java] smaller synchronization window
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.java/src/org/eclipse')
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageService.java75
1 files changed, 41 insertions, 34 deletions
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 9ca624c85..99d7bc3ef 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
@@ -61,10 +61,34 @@ public class MessageService extends RTObject implements IMessageService {
return address;
}
- public synchronized void run() {
+ public void run() {
running = true;
+
while (running) {
- pollOneMessage();
+ Message msg = null;
+
+ // get next Message from Queue
+ synchronized(this) {
+ msg = messageQueue.pop();
+ }
+
+ if (msg == null) {
+ // no message in queue -> wait until Thread is notified
+ try {
+ synchronized(this) {
+ if (!running)
+ return;
+ wait();
+ }
+ }
+ catch (InterruptedException e) {
+ }
+ }
+ else {
+ // process message
+ lastMessageTimestamp = System.currentTimeMillis();
+ messageDispatcher.receive(msg);
+ }
}
}
@@ -76,44 +100,14 @@ public class MessageService extends RTObject implements IMessageService {
}
}
- private synchronized void pollOneMessage() {
- Message msg = messageQueue.pop(); // get next Message from Queue
- if (msg == null) {
- // no message in queue -> wait till Thread is notified
- try {
- wait();
- }
- catch (InterruptedException e) {
- }
- }
- else {
- lastMessageTimestamp = System.currentTimeMillis();
- messageDispatcher.receive(msg);
- }
-
- }
-
- public Address getFreeAddress() {
+ public synchronized Address getFreeAddress() {
return messageDispatcher.getFreeAddress();
}
- public void freeAddress(Address addr) {
+ public synchronized void freeAddress(Address addr) {
messageDispatcher.freeAddress(addr);
}
- // protected methods for sole use by test cases
- protected MessageSeQueue getMessageQueue() {
- return messageQueue;
- }
-
- protected synchronized MessageDispatcher getMessageDispatcher() {
- return messageDispatcher;
- }
-
- protected synchronized long getLastMessageTimestamp() {
- return lastMessageTimestamp;
- }
-
public synchronized void terminate() {
if (running) {
running = false;
@@ -146,5 +140,18 @@ public class MessageService extends RTObject implements IMessageService {
public void removeMessageReceiver(IMessageReceiver receiver) {
messageDispatcher.removeMessageReceiver(receiver);
}
+
+ // protected methods for sole use by test cases
+ protected MessageSeQueue getMessageQueue() {
+ return messageQueue;
+ }
+
+ protected synchronized MessageDispatcher getMessageDispatcher() {
+ return messageDispatcher;
+ }
+
+ protected synchronized long getLastMessageTimestamp() {
+ return lastMessageTimestamp;
+ }
}

Back to the top