[PATCH 11/30] score: Add thread scheduler lock

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Oct 31 08:51:42 UTC 2016


Update #2556.
---
 cpukit/score/include/rtems/score/thread.h     |  5 +++++
 cpukit/score/include/rtems/score/threadimpl.h | 16 ++++++++++++++++
 cpukit/score/src/threadinitialize.c           |  1 +
 cpukit/score/src/threadrestart.c              |  1 +
 4 files changed, 23 insertions(+)

diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index a86d81b..e9f3465 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -246,6 +246,11 @@ typedef enum {
 typedef struct {
 #if defined(RTEMS_SMP)
   /**
+   * @brief Lock to protect the scheduler node change requests.
+   */
+  ISR_lock_Control Lock;
+
+  /**
    * @brief The current scheduler state of this thread.
    */
   Thread_Scheduler_state state;
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 22b3094..b7e1b87 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -1028,6 +1028,22 @@ RTEMS_INLINE_ROUTINE Scheduler_Node *_Thread_Scheduler_get_node_by_index(
 }
 
 #if defined(RTEMS_SMP)
+RTEMS_INLINE_ROUTINE void _Thread_Scheduler_acquire_critical(
+  Thread_Control   *the_thread,
+  ISR_lock_Context *lock_context
+)
+{
+  _ISR_lock_Acquire( &the_thread->Scheduler.Lock, lock_context );
+}
+
+RTEMS_INLINE_ROUTINE void _Thread_Scheduler_release_critical(
+  Thread_Control   *the_thread,
+  ISR_lock_Context *lock_context
+)
+{
+  _ISR_lock_Release( &the_thread->Scheduler.Lock, lock_context );
+}
+
 RTEMS_INLINE_ROUTINE void _Thread_Scheduler_add_wait_node(
   Thread_Control *the_thread,
   Scheduler_Node *scheduler_node
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index c6db62f..62c3066 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -234,6 +234,7 @@ bool _Thread_Initialize(
   the_thread->Scheduler.own_node = scheduler_node;
   the_thread->Scheduler.node = scheduler_node;
   _Resource_Node_initialize( &the_thread->Resource_node );
+  _ISR_lock_Initialize( &the_thread->Scheduler.Lock, "Thread Scheduler" );
   _ISR_lock_Initialize( &the_thread->Wait.Lock.Default, "Thread Wait Default" );
   _Thread_queue_Gate_open( &the_thread->Wait.Lock.Tranquilizer );
   _RBTree_Initialize_node( &the_thread->Wait.Link.Registry_node );
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index 6953400..5cd9d43 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -200,6 +200,7 @@ static void _Thread_Free( Thread_Control *the_thread )
   _Workspace_Free( the_thread->Start.tls_area );
 
 #if defined(RTEMS_SMP)
+  _ISR_lock_Destroy( &the_thread->Scheduler.Lock );
   _ISR_lock_Destroy( &the_thread->Wait.Lock.Default );
   _SMP_lock_Stats_destroy( &the_thread->Potpourri_stats );
 #endif
-- 
1.8.4.5




More information about the devel mailing list