Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2016-11-21 20:38:10 +0000
committerHenrik Rentz-Reichert2016-11-21 20:38:10 +0000
commit0e349e78bdf554a49fc35739e2b1ecc865f4fe3e (patch)
tree84097ff984033a85e509a40b269bc7f7be93f4dc /runtime
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
Diffstat (limited to 'runtime')
-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
3 files changed, 33 insertions, 15 deletions
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