commit e566c39e42232414f5fd89c1b8a33721447aaf57
Author: skenneweg <skenneweg@techfak.uni-bielefeld.de>
Date:   Wed Jun 3 13:00:27 2020 +0200

    Finished some todos in functions of the core
    (mutex lock, broadcast control event, increment/check node's stage value)

diff --git a/Makefile b/Makefile
index ce6ab92..8cd04f2 100644
--- a/Makefile
+++ b/Makefile
@@ -30,9 +30,7 @@ URTWARE_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
 
 # include paths
 URTWARE_INC = $(URTWARE_DIR:/=) \
-              $(URTWARE_DIR)inc \
-							$(URTWARE_DIR)inc/urt_core.h \
-							$(URTWARE_DIR)inc/urt_node.h
+              $(URTWARE_DIR)inc 
 
 # C sources
 URTWARE_CSRC = $(URTWARE_DIR)src/urt_core.c \
diff --git a/inc/urt_core.h b/inc/urt_core.h
index d979276..f3476a2 100644
--- a/inc/urt_core.h
+++ b/inc/urt_core.h
@@ -72,7 +72,7 @@ extern "C" {
   void urtCoreInit(void);
   urt_status_t urtCoreGetStatus(void);
   void urtCoreStartNodes(void);
-  urt_status_t urtCoreSynchronize(urt_node_t* node);
+  urt_status_t urtCoreSynchronizeNodes(urt_node_t* node);
   urt_status_t urtCoreStopNodes(urt_status_t reason);
 
 #if (URT_CFG_PUBSUB_ENABLED)
diff --git a/src/urt_core.c b/src/urt_core.c
index b05186b..4c7229e 100644
--- a/src/urt_core.c
+++ b/src/urt_core.c
@@ -80,14 +80,14 @@ urt_status_t urtCoreGetStatus(void)
  */
 void urtCoreStartNodes(void)
 {
-  //TODO: Lock core
+  urtMutexLock(&core._lock);
   urt_node_t* node = core._nodes;
   while (node)
   {
     urtThreadStart(node->thread);
     node = node->next;
   }
-  //TODO: Unlock core
+  urtMutexUnlock(&core._lock);
   return;
 }
 
@@ -101,29 +101,31 @@ void urtCoreStartNodes(void)
  *          Returns URT_STATUS_SYNC_PENDING if there are nodes left to synchronize.
  *          In the latter case, the node thread must still wait for the control event (proceed) to synchronize.
  */
-urt_status_t urtCoreSynchronize(urt_node_t* node)
+urt_status_t urtCoreSynchronizeNodes(urt_node_t* node)
 {
-  //TODO: Lock core
-  //TODO: Increment node's stage value
+  urtMutexLock(&core._lock);
+  node->stage -= 1;
   urt_node_t* nodeFromCore = core._nodes;
-  while (nodeFromCore /*stage equals stage*/)
+  while (nodeFromCore && nodeFromCore->stage == node->stage)
   {
     nodeFromCore = nodeFromCore->next;
   }
-  bool temp = false;
-  if (temp/*all nodes are the same stage*/)
+  if (nodeFromCore)
   {
-    //TODO: Unlock core
+    urt_osEventFlags_t flag = 0; /*TODO: set to proceed? */
+    urtEventSourceBroadcast(core._evtSource, flag);
+    urtMutexUnlock(&core._lock);
     return URT_STATUS_OK;
   }
-  else if (temp/*stage of the last checked node was one less than the argument*/)
+  else if (nodeFromCore->stage == (node->stage - 1))
   {
-    //TODO: Unlock core
+    urtMutexUnlock(&core._lock);
     return URT_STATUS_SYNC_PENDING;
   }
   else
   {
       urtCoreStopNodes(URT_STATUS_SYNC_ERROR);
+      urtMutexUnlock(&core._lock);
       return URT_STATUS_SYNC_ERROR;
   }
 }
@@ -138,34 +140,37 @@ urt_status_t urtCoreSynchronize(urt_node_t* node)
  */
 urt_status_t urtCoreStopNodes(urt_status_t reason)
 {
-  //TODO: Lock core
+  urtMutexLock(&core._lock);
+  bool priorityBoosted = false;
+  urt_osThreadPrio_t oldPrio;
+
   if (core._status == URT_STATUS_OK)
   {
     if (core._nodes->thread->prio < URT_THREAD_PRIO_HIGH_MAX)
     {
+      oldPrio = core._nodes->thread->prio;
+      priorityBoosted = true;
       core._nodes->thread->prio = URT_THREAD_PRIO_HIGH_MAX;
     }
-    else
+    core._status = reason;
+    urt_node_t* node = core._nodes;
+    while (node)
     {
-      core._status = reason;
-      urt_node_t* node = core._nodes;
-      while (node)
-      {
-        urt_node_t* tempNode = node;
-        tempNode = NULL;
-        node = node->next;
-      }
-      //TODO: broadcast control event (terminate)
-      //TODO:Unlock core
-      //TODO: Thread boosted its priority?
+      urtThreadTerminate(node->thread, URT_THREAD_TERMINATE_REQUEST);
+      node = node->next;
     }
+    urt_osEventFlags_t flag = 0; /*TODO: set to terminate? */
+    urtEventSourceBroadcast(core._evtSource, flag);
+    urtMutexUnlock(&core._lock);
+    if (priorityBoosted)
+      core._nodes->thread->prio = oldPrio;
+    return URT_STATUS_OK;
   }
   else
   {
-      //TODO:Unlock core
-      return core._status;
+    urtMutexUnlock(&core._lock);
+    return core._status;
   }
-  return URT_STATUS_OK;
 }
 
 /**
