Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2016-11-21 15:38:10 -0500
committerHenrik Rentz-Reichert2016-11-21 15:38:10 -0500
commit0e349e78bdf554a49fc35739e2b1ecc865f4fe3e (patch)
tree84097ff984033a85e509a40b269bc7f7be93f4dc
parentaaef21c8059b4b00d2088600fb77a6ebedf38fdf (diff)
downloadorg.eclipse.etrice-0e349e78bdf554a49fc35739e2b1ecc865f4fe3e.tar.gz
org.eclipse.etrice-0e349e78bdf554a49fc35739e2b1ecc865f4fe3e.tar.xz
org.eclipse.etrice-0e349e78bdf554a49fc35739e2b1ecc865f4fe3e.zip
Bug 348173 - message services should be started according to thread prio
* generated code for creating and adding message services is sorted in descending priority * runtimes changed to consider order Change-Id: I5d2043fdbd8f4b9657b92e2f2cb7785b07849019
-rw-r--r--plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend4
-rw-r--r--plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java21
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend2
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/NodeGen.java10
-rw-r--r--plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeGen.xtend2
-rw-r--r--plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/NodeGen.java22
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp29
-rw-r--r--runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h4
-rw-r--r--runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java15
9 files changed, 75 insertions, 34 deletions
diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend
index 1e849d8c2..798959f4a 100644
--- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/NodeGen.xtend
@@ -187,7 +187,7 @@ class NodeGen {
etTime interval;
/* initialization of all message services */
- «FOR thread: threads»
+ «FOR thread: threads.sortBy[-prio]»
«IF thread.execmode==ExecMode::POLLED || thread.execmode==ExecMode::MIXED»
interval.sec = «TimeConverter::split(thread.time, TimeConverter.SEC, true)»;
interval.nSec = «TimeConverter::split(thread.time, TimeConverter.MILLI_SEC, false)»;
@@ -212,7 +212,7 @@ class NodeGen {
static void «clsname»_startMessageServices(void) {
ET_MSC_LOGGER_SYNC_ENTRY("«clsname»", "startMessageServices")
- «FOR thread: threads.sortBy[getPrio].reverse»
+ «FOR thread: threads.sortBy[-prio]»
etMessageService_start(&msgService_«thread.name»);
«ENDFOR»
diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java
index a945d3724..750650568 100644
--- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java
+++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/NodeGen.java
@@ -80,7 +80,6 @@ import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IntegerRange;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
-import org.eclipse.xtext.xbase.lib.ListExtensions;
@Singleton
@SuppressWarnings("all")
@@ -412,7 +411,15 @@ public class NodeGen {
_builder.append("/* initialization of all message services */");
_builder.newLine();
{
- for(final PhysicalThread thread : threads) {
+ final Function1<PhysicalThread, Long> _function_1 = new Function1<PhysicalThread, Long>() {
+ @Override
+ public Long apply(final PhysicalThread it) {
+ long _prio = it.getPrio();
+ return Long.valueOf((-_prio));
+ }
+ };
+ List<PhysicalThread> _sortBy = IterableExtensions.<PhysicalThread, Long>sortBy(threads, _function_1);
+ for(final PhysicalThread thread : _sortBy) {
{
if ((Objects.equal(thread.getExecmode(), ExecMode.POLLED) || Objects.equal(thread.getExecmode(), ExecMode.MIXED))) {
_builder.append("\t\t");
@@ -518,15 +525,15 @@ public class NodeGen {
_builder.newLineIfNotEmpty();
_builder.newLine();
{
- final Function1<PhysicalThread, Long> _function_1 = new Function1<PhysicalThread, Long>() {
+ final Function1<PhysicalThread, Long> _function_2 = new Function1<PhysicalThread, Long>() {
@Override
public Long apply(final PhysicalThread it) {
- return Long.valueOf(it.getPrio());
+ long _prio = it.getPrio();
+ return Long.valueOf((-_prio));
}
};
- List<PhysicalThread> _sortBy = IterableExtensions.<PhysicalThread, Long>sortBy(threads, _function_1);
- List<PhysicalThread> _reverse = ListExtensions.<PhysicalThread>reverse(_sortBy);
- for(final PhysicalThread thread_1 : _reverse) {
+ List<PhysicalThread> _sortBy_1 = IterableExtensions.<PhysicalThread, Long>sortBy(threads, _function_2);
+ for(final PhysicalThread thread_1 : _sortBy_1) {
_builder.append("\t");
_builder.append("etMessageService_start(&msgService_");
String _name_11 = thread_1.getName();
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend
index 7ac206db5..48a98f833 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend
@@ -234,7 +234,7 @@ class NodeGen {
«ENDIF»
IMessageMemory* msgMemory;
- «FOR thread: threads»
+ «FOR thread: threads.sortBy[-prio]»
{
msgMemory = new StaticMessageMemory(this, "MessageMemory_«thread.name»", «thread.msgblocksize», «thread.msgpoolsize»);
«IF thread.execmode==ExecMode::POLLED || thread.execmode==ExecMode::MIXED»
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/NodeGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/NodeGen.java
index f93f1f980..8b127a7db 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/NodeGen.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/NodeGen.java
@@ -574,7 +574,15 @@ public class NodeGen {
_builder.append("IMessageMemory* msgMemory;");
_builder.newLine();
{
- for(final PhysicalThread thread_3 : threads) {
+ final Function1<PhysicalThread, Long> _function_1 = new Function1<PhysicalThread, Long>() {
+ @Override
+ public Long apply(final PhysicalThread it) {
+ long _prio = it.getPrio();
+ return Long.valueOf((-_prio));
+ }
+ };
+ List<PhysicalThread> _sortBy = IterableExtensions.<PhysicalThread, Long>sortBy(threads, _function_1);
+ for(final PhysicalThread thread_3 : _sortBy) {
_builder.append("\t");
_builder.append("{");
_builder.newLine();
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeGen.xtend
index ef86670fd..793c38e3e 100644
--- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/NodeGen.xtend
@@ -151,7 +151,7 @@ class NodeGen {
public void instantiateMessageServices() {
IMessageService msgService;
- «FOR thread: threads»
+ «FOR thread: threads.sortBy[-prio]»
«IF thread.execmode==ExecMode::POLLED || thread.execmode==ExecMode::MIXED»
msgService = new MessageService(this, MessageService.ExecMode.«thread.execmode.getName», «thread.time»L, 0, «thread.threadId», "MessageService_«thread.name»" /*, thread_prio */);
«ELSE»
diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/NodeGen.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/NodeGen.java
index 9db9a44e7..d1eba88ce 100644
--- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/NodeGen.java
+++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/NodeGen.java
@@ -331,7 +331,15 @@ public class NodeGen {
_builder.append("IMessageService msgService;");
_builder.newLine();
{
- for(final PhysicalThread thread_1 : threads) {
+ final Function1<PhysicalThread, Long> _function_1 = new Function1<PhysicalThread, Long>() {
+ @Override
+ public Long apply(final PhysicalThread it) {
+ long _prio = it.getPrio();
+ return Long.valueOf((-_prio));
+ }
+ };
+ List<PhysicalThread> _sortBy = IterableExtensions.<PhysicalThread, Long>sortBy(threads, _function_1);
+ for(final PhysicalThread thread_1 : _sortBy) {
{
if ((Objects.equal(thread_1.getExecmode(), ExecMode.POLLED) || Objects.equal(thread_1.getExecmode(), ExecMode.MIXED))) {
_builder.append("\t\t");
@@ -487,20 +495,20 @@ public class NodeGen {
_builder.newLine();
{
BasicEList<AbstractInstance> _allSubInstances = this._roomExtensions.getAllSubInstances(comp);
- final Function1<AbstractInstance, Boolean> _function_1 = new Function1<AbstractInstance, Boolean>() {
+ final Function1<AbstractInstance, Boolean> _function_2 = new Function1<AbstractInstance, Boolean>() {
@Override
public Boolean apply(final AbstractInstance inst) {
return Boolean.valueOf((inst instanceof ActorInterfaceInstance));
}
};
- Iterable<AbstractInstance> _filter = IterableExtensions.<AbstractInstance>filter(_allSubInstances, _function_1);
- final Function1<AbstractInstance, ActorInterfaceInstance> _function_2 = new Function1<AbstractInstance, ActorInterfaceInstance>() {
+ Iterable<AbstractInstance> _filter = IterableExtensions.<AbstractInstance>filter(_allSubInstances, _function_2);
+ final Function1<AbstractInstance, ActorInterfaceInstance> _function_3 = new Function1<AbstractInstance, ActorInterfaceInstance>() {
@Override
public ActorInterfaceInstance apply(final AbstractInstance inst) {
return ((ActorInterfaceInstance) inst);
}
};
- Iterable<ActorInterfaceInstance> _map = IterableExtensions.<AbstractInstance, ActorInterfaceInstance>map(_filter, _function_2);
+ Iterable<ActorInterfaceInstance> _map = IterableExtensions.<AbstractInstance, ActorInterfaceInstance>map(_filter, _function_3);
for(final ActorInterfaceInstance aii : _map) {
_builder.append("\t\t");
_builder.append("{");
@@ -760,14 +768,14 @@ public class NodeGen {
{
EList<ActorClass> _subClasses = root.getSubClasses(oa);
List<ActorClass> _union = this._roomExtensions.<ActorClass>union(_subClasses, oa);
- final Function1<ActorClass, Boolean> _function_3 = new Function1<ActorClass, Boolean>() {
+ final Function1<ActorClass, Boolean> _function_4 = new Function1<ActorClass, Boolean>() {
@Override
public Boolean apply(final ActorClass s) {
boolean _isAbstract = s.isAbstract();
return Boolean.valueOf((!_isAbstract));
}
};
- Iterable<ActorClass> _filter_1 = IterableExtensions.<ActorClass>filter(_union, _function_3);
+ Iterable<ActorClass> _filter_1 = IterableExtensions.<ActorClass>filter(_union, _function_4);
for(final ActorClass subcls : _filter_1) {
_builder.append("\t\t");
_builder.append("\t");
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp
index 89ab179b4..7ca18e7ee 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp
@@ -10,12 +10,14 @@
*
*******************************************************************************/
+#include <algorithm>
#include "MessageServiceController.h"
namespace etRuntime {
MessageServiceController::MessageServiceController() :
m_messageServices(),
+ m_messageServicesOrdered(),
m_freeIDs(),
m_running(false),
m_nextFreeID(0),
@@ -50,12 +52,15 @@ void MessageServiceController::addMsgSvc(IMessageService& msgSvc) {
m_nextFreeID = msgSvc.getAddress().m_threadID + 1;
m_messageServices[msgSvc.getAddress().m_threadID] = &msgSvc;
+ m_messageServicesOrdered.push_back(&msgSvc);
etMutex_leave(&m_mutex);
}
void MessageServiceController::removeMsgSvc(IMessageService& msgSvc) {
etMutex_enter(&m_mutex);
m_messageServices.erase(msgSvc.getAddress().m_threadID);
+ std::vector<IMessageService*>::iterator it = std::find(m_messageServicesOrdered.begin(), m_messageServicesOrdered.end(), &msgSvc);
+ m_messageServicesOrdered.erase(it);
etMutex_leave(&m_mutex);
}
@@ -71,12 +76,15 @@ IMessageService* MessageServiceController::getMsgSvc(int id) {
}
void MessageServiceController::start() {
+ etMutex_enter(&m_mutex);
+
// start all message services
- for (std::map<int, IMessageService*>::iterator it = m_messageServices.begin(); it != m_messageServices.end(); ++it) {
- (it->second)->start();
- // TODO TS: start in order of priorities
+ for (std::vector<IMessageService*>::iterator it = m_messageServicesOrdered.begin(); it != m_messageServicesOrdered.end(); ++it) {
+ (*it)->start();
}
m_running = true;
+
+ etMutex_leave(&m_mutex);
}
void MessageServiceController::stop() {
@@ -111,12 +119,12 @@ void MessageServiceController::dumpThreads(std::string msg) {
void MessageServiceController::terminate() {
// terminate all message services
etMutex_enter(&m_mutex);
- m_terminateServices = m_messageServices;
+ m_terminateServices = m_messageServicesOrdered;
- std::map<int, IMessageService*>::iterator it = m_terminateServices.begin();
- for (; it != m_terminateServices.end(); ++it) {
- (it->second)->terminate();
- //TODO TS: stop in order of priorities
+ // stop in reverse order
+ std::vector<IMessageService*>::reverse_iterator it = m_terminateServices.rbegin();
+ for (; it != m_terminateServices.rend(); ++it) {
+ (*it)->terminate();
}
etMutex_leave(&m_mutex);
}
@@ -147,7 +155,10 @@ void MessageServiceController::resetAll() {
void MessageServiceController::setMsgSvcTerminated(const IMessageService& msgSvc){
etMutex_enter(&m_mutex);
- m_terminateServices.erase(msgSvc.getAddress().m_threadID);
+ std::vector<IMessageService*>::iterator it = std::find(m_terminateServices.begin(), m_terminateServices.end(), &msgSvc);
+ if (it!=m_terminateServices.end()) {
+ m_terminateServices.erase(it);
+ }
etSema_wakeup(&m_terminateSema);
etMutex_leave(&m_mutex);
}
diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h
index 4771b38b9..81724e82d 100644
--- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h
+++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h
@@ -17,6 +17,7 @@
#include "osal/etMutex.h"
#include "osal/etSema.h"
#include <map>
+#include <vector>
#include <queue>
#include <string>
@@ -51,13 +52,14 @@ private:
void terminate();
std::map<int, IMessageService*> m_messageServices;
+ std::vector<IMessageService*> m_messageServicesOrdered;
std::queue<int> m_freeIDs;
etBool m_running;
int m_nextFreeID;
etMutex m_mutex;
etSema m_terminateSema;
- std::map<int, IMessageService*> m_terminateServices;
+ std::vector<IMessageService*> m_terminateServices;
MessageServiceController(MessageServiceController const&);
MessageServiceController& operator=(MessageServiceController const&);
diff --git a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java
index fd1089c79..367b804ca 100644
--- a/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java
+++ b/runtime/org.eclipse.etrice.runtime.java/src/org/eclipse/etrice/runtime/java/messaging/MessageServiceController.java
@@ -16,6 +16,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -32,6 +33,7 @@ import java.util.Map;
public class MessageServiceController {
private HashMap<Integer, IMessageService> messageServices = new HashMap<Integer, IMessageService>();
+ private LinkedList<IMessageService> orderedMessageServices = new LinkedList<IMessageService>();
private LinkedList<Integer> freeIDs = new LinkedList<Integer>();
private boolean running = false;
private int nextFreeID = 0;
@@ -52,10 +54,12 @@ public class MessageServiceController {
nextFreeID = msgSvc.getAddress().threadID+1;
messageServices.put(msgSvc.getAddress().threadID, msgSvc);
+ orderedMessageServices.add(msgSvc);
}
public synchronized void removeMsgSvc(IMessageService msgSvc){
messageServices.remove(msgSvc.getAddress().threadID);
+ orderedMessageServices.remove(msgSvc);
}
public synchronized IMessageService getMsgSvc(int id){
@@ -77,7 +81,7 @@ public class MessageServiceController {
// start all message services
List<Thread> threads = new ArrayList<Thread>(messageServices.size());
- for (IMessageService msgSvc : messageServices.values()){
+ for (IMessageService msgSvc : orderedMessageServices){
Thread thread = new Thread(msgSvc, msgSvc.getName());
msgSvc.setThread(thread);
threads.add(thread);
@@ -124,9 +128,8 @@ public class MessageServiceController {
private void terminate() {
// terminate all message services
- for (IMessageService msgSvc : messageServices.values()){
- msgSvc.terminate();
- // TODOTS: stop in order of priorities
+ for (Iterator<IMessageService> it = orderedMessageServices.descendingIterator(); it.hasNext(); ) {
+ it.next().terminate();
}
}
@@ -135,8 +138,9 @@ public class MessageServiceController {
* ! not thread safe !
*/
public void waitTerminate() {
- for (IMessageService msgSvc : messageServices.values()) {
+ for (Iterator<IMessageService> it = orderedMessageServices.descendingIterator(); it.hasNext(); ) {
try {
+ IMessageService msgSvc = it.next();
if (msgSvc.getThread()==null)
continue;
@@ -153,6 +157,7 @@ public class MessageServiceController {
public synchronized void resetAll() {
stop();
messageServices.clear();
+ orderedMessageServices.clear();
freeIDs.clear();
nextFreeID = 0;
}

Back to the top