Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/org.eclipse.etrice.runtime.c/src/common/runtime')
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c296
-rw-r--r--runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.h63
2 files changed, 314 insertions, 45 deletions
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c b/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c
index 4bc54e6e8..7b1ac14fe 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.c
@@ -12,99 +12,309 @@
#include "runtime/etRuntime.h"
+#include "debugging/etMSCLogger.h"
static etSema terminateSemaphore;
-static etMessageService* head = NULL;
+static etMessageService* etRuntime_msgsvc_head;
+static etMemory* etRuntime_memmgmt_head;
etSema* etRuntime_getTerminateSemaphore() {
static etBool initialized = ET_FALSE;
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "getTerminateSemaphore")
if (!initialized) {
initialized = ET_TRUE;
etSema_construct(&terminateSemaphore);
}
+ ET_MSC_LOGGER_SYNC_EXIT
return &terminateSemaphore;
}
-int etRuntime_getMessageServiceCount() {
- etMessageService* p = head;
+static void etRuntime_initInternal() {
+ // global variables might not be initialized before a function call - so we use this trick
+ static etBool initialized = ET_FALSE;
+
+ if (!initialized) {
+ initialized = ET_TRUE;
+ etRuntime_msgsvc_head = NULL;
+ etRuntime_memmgmt_head = NULL;
+ }
+
+}
+int etRuntime_getMessageServiceCount() {
int count = 0;
- while (p!=null) {
- ++count;
- p = p->next;
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "getMessageServiceCount")
+ etRuntime_initInternal();
+ {
+ etMessageService* p = etRuntime_msgsvc_head;
+ while (p!=null) {
+ ++count;
+ p = p->next;
+ }
}
+
+ ET_MSC_LOGGER_SYNC_EXIT
return count;
}
int etRuntime_getMessageServiceByName(const char* name) {
- etMessageService* p = head;
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "getMessageServiceByName")
- int idx = 0;
- while (p!=null) {
- if (strcmp(p->name, name)==0) {
- return idx;
+ {
+ etMessageService* p = etRuntime_msgsvc_head;
+ int idx = 0;
+ while (p!=null) {
+ if (strcmp(p->name, name)==0) {
+ ET_MSC_LOGGER_SYNC_EXIT
+ return idx;
+ }
+ ++idx;
+ p = p->next;
}
- ++idx;
- p = p->next;
}
+ ET_MSC_LOGGER_SYNC_EXIT
return -1;
}
const etMessageServiceStatistics* etRuntime_getMessageServiceStatistics(unsigned int i) {
- etMessageService* p = head;
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "getMessageServiceStatistics")
- int count = 0;
- while (p!=null) {
- if (count==i) {
- return &p->statistics;
+ {
+ etMessageService* p = etRuntime_msgsvc_head;
+ int count = 0;
+ while (p!=null) {
+ if (count==i) {
+ ET_MSC_LOGGER_SYNC_EXIT
+ return &p->statistics;
+ }
+ ++count;
+ p = p->next;
}
- ++count;
- p = p->next;
}
+ ET_MSC_LOGGER_SYNC_EXIT
+ return NULL;
+}
+
+const char* etRuntime_getMessageServiceName(unsigned int i) {
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "getMessageServiceName")
+
+ {
+ etMessageService* p = etRuntime_msgsvc_head;
+ int count = 0;
+ while (p!=null) {
+ if (count==i) {
+ ET_MSC_LOGGER_SYNC_EXIT
+ return p->name;
+ }
+ ++count;
+ p = p->next;
+ }
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
return NULL;
}
void etRuntime_resetAllMessageServiceStatistics() {
- etMessageService* p = head;
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "resetAllMessageServiceStatistics")
- while (p!=null) {
- p->resetStatistics = ET_TRUE;
- p = p->next;
+ {
+ etMessageService* p = etRuntime_msgsvc_head;
+ while (p!=null) {
+ p->resetStatistics = ET_TRUE;
+ p = p->next;
+ }
}
+
+ ET_MSC_LOGGER_SYNC_EXIT
}
void etRuntime_registerMessageService(etMessageService* msgService) {
- msgService->next = head;
- head = msgService;
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "registerMessageService")
- if (msgService->name==NULL) {
- void* p = malloc(16);
- sprintf(p, "MsgSvc_%d", etRuntime_getMessageServiceCount());
- msgService->name = (const char*) p;
+ {
+ msgService->next = etRuntime_msgsvc_head;
+ etRuntime_msgsvc_head = msgService;
+ if (msgService->name==NULL) {
+ void* p = malloc(16);
+ sprintf(p, "MsgSvc_%d", etRuntime_getMessageServiceCount());
+ msgService->name = (const char*) p;
+ }
}
+
+ ET_MSC_LOGGER_SYNC_EXIT
}
void etRuntime_unregisterMessageService(etMessageService* msgService) {
- etMessageService* p = head;
- etMessageService* last = NULL;
-
- while (p!=null) {
- if (p==msgService) {
- if (last==NULL) {
- /* remove the first one */
- head = p->next;
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "unregisterMessageService")
+
+ {
+ etMessageService* p = etRuntime_msgsvc_head;
+ etMessageService* last = NULL;
+ while (p!=null) {
+ if (p==msgService) {
+ if (last==NULL) {
+ /* remove the first one */
+ etRuntime_msgsvc_head = p->next;
+ }
+ else {
+ last->next = p->next;
+ }
+ break;
+ }
+ last = p;
+ p = p->next;
+ }
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etRuntime_registerMemoryManagement(etMemory* mem) {
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "registerMemoryManagement")
+
+ {
+ mem->next = etRuntime_memmgmt_head;
+ etRuntime_memmgmt_head = mem;
+ if (mem->name==NULL) {
+ void* p = malloc(16);
+ sprintf(p, "MemMgmt_%d", etRuntime_getMemoryManagementCount());
+ mem->name = (const char*) p;
+ }
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+void etRuntime_unregisterMemoryManagement(etMemory* mem) {
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "unregisterMemoryManagement")
+
+ {
+ etMemory* p = etRuntime_memmgmt_head;
+ etMemory* last = NULL;
+ while (p!=null) {
+ if (p==mem) {
+ if (last==NULL) {
+ /* remove the first one */
+ etRuntime_memmgmt_head = p->next;
+ }
+ else {
+ last->next = p->next;
+ }
+ break;
}
- else {
- last->next = p->next;
+ last = p;
+ p = p->next;
+ }
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+}
+
+int etRuntime_getMemoryManagementCount() {
+ int count = 0;
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "getMemoryManagementCount")
+
+ {
+ etMemory* p = etRuntime_memmgmt_head;
+ while (p!=null) {
+ ++count;
+ p = p->next;
+ }
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return count;
+}
+
+int etRuntime_getMemoryManagementByName(const char* name) {
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "getMemoryManagementByName")
+
+ {
+ etMemory* p = etRuntime_memmgmt_head;
+ int idx = 0;
+ while (p!=null) {
+ if (strcmp(p->name, name)==0) {
+ ET_MSC_LOGGER_SYNC_EXIT
+ return idx;
}
- break;
+ ++idx;
+ p = p->next;
}
- last = p;
- p = p->next;
}
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return -1;
+}
+
+const etMemoryStatistics* etRuntime_getMemoryManagementStatistics(unsigned int i) {
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "getMemoryManagementStatistics")
+
+ {
+ etMemory* p = etRuntime_memmgmt_head;
+ int count = 0;
+ while (p!=null) {
+ if (count==i) {
+ ET_MSC_LOGGER_SYNC_EXIT
+ return &p->statistics;
+ }
+ ++count;
+ p = p->next;
+ }
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return NULL;
+}
+
+const char* etRuntime_getMemoryManagementName(unsigned int i) {
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "getMemoryManagementName")
+
+ {
+ etMemory* p = etRuntime_memmgmt_head;
+ int count = 0;
+ while (p!=null) {
+ if (count==i) {
+ ET_MSC_LOGGER_SYNC_EXIT
+ return p->name;
+ }
+ ++count;
+ p = p->next;
+ }
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
+ return NULL;
+}
+
+void etRuntime_resetAllMemoryManagementStatistics() {
+ etRuntime_initInternal();
+ ET_MSC_LOGGER_SYNC_ENTRY("etRuntime", "resetAllMemoryManagementStatistics")
+
+ {
+ etMemory* p = etRuntime_memmgmt_head;
+ while (p!=null) {
+ etMemory_resetStatistics(p);
+ p = p->next;
+ }
+ }
+
+ ET_MSC_LOGGER_SYNC_EXIT
}
diff --git a/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.h b/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.h
index 5c5ff3d0b..4dab21678 100644
--- a/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.h
+++ b/runtime/org.eclipse.etrice.runtime.c/src/common/runtime/etRuntime.h
@@ -18,6 +18,7 @@ extern "C" {
#define _ETRUNTIME_H_
#include "messaging/etMessageService.h"
+#include "base/etMemory.h"
/**
* \file etRuntime.h
@@ -45,6 +46,14 @@ int etRuntime_getMessageServiceCount();
const etMessageServiceStatistics* etRuntime_getMessageServiceStatistics(unsigned int i);
/**
+ * returns the name of a message service
+ *
+ * \param i the message service instance number
+ * \return the name of this message service
+ */
+const char* etRuntime_getMessageServiceName(unsigned int i);
+
+/**
* finds a message service by its name and returns its index or -1 if not found
*
* \param name the name of the message service
@@ -58,16 +67,66 @@ int etRuntime_getMessageServiceByName(const char* name);
void etRuntime_resetAllMessageServiceStatistics();
/**
- * registers the message service by hooking it into a linked list
+ * registers a message service
+ * \param msgService the message service
*/
void etRuntime_registerMessageService(etMessageService* msgService);
/**
- * unregisters the message service by removing it from the linked list
+ * unregisters a message service
+ * \param msgService the message service
*/
void etRuntime_unregisterMessageService(etMessageService* msgService);
/**
+ * registers a memory management
+ * \param mem the memory management
+ */
+void etRuntime_registerMemoryManagement(etMemory* mem);
+
+/**
+ * unregisters a memory management
+ * \param mem the memory management
+ */
+void etRuntime_unregisterMemoryManagement(etMemory* mem);
+
+/**
+ * returns the number of memory managements in this process
+ *
+ * \return the number of memory managements in this process
+ */
+int etRuntime_getMemoryManagementCount();
+
+/**
+ * returns the statistics of a memory management
+ *
+ * \param i the memory management instance number
+ * \return the statistics of this memory management
+ */
+const etMemoryStatistics* etRuntime_getMemoryManagementStatistics(unsigned int i);
+
+/**
+ * finds a memory management by its name and returns its index or -1 if not found
+ *
+ * \param name the name of the memory management
+ * \return the index of the memory management or -1
+ */
+int etRuntime_getMemoryManagementByName(const char* name);
+
+/**
+ * returns the name of a memory management
+ *
+ * \param i the memory management instance number
+ * \return the name of this memory management
+ */
+const char* etRuntime_getMemoryManagementName(unsigned int i);
+
+/**
+ * sets a flag in all memory management structs that tells the memory managements to reset their statistics
+ */
+void etRuntime_resetAllMemoryManagementStatistics();
+
+/**
* a global semaphore used to terminate the application in headless mode
*
* \return the semaphore

Back to the top