[rtems commit] score: Avoid direct usage of _Thread_Executing

Sebastian Huber sebh at rtems.org
Mon Jul 22 14:51:43 UTC 2013


Module:    rtems
Branch:    master
Commit:    0444947e63715829d484b411f63244585ad6f449
Changeset: http://git.rtems.org/rtems/commit/?id=0444947e63715829d484b411f63244585ad6f449

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Jul 19 11:07:37 2013 +0200

score: Avoid direct usage of _Thread_Executing

Pass the executing thread as a function parameter.  Obtain the executing
thread inside a thread dispatch critical section to avoid problems on
SMP.

---

 cpukit/posix/src/pbarrierwait.c                    |    5 ++++-
 cpukit/rtems/src/barrierwait.c                     |    5 ++++-
 cpukit/score/include/rtems/score/corebarrierimpl.h |    2 ++
 cpukit/score/src/corebarrierwait.c                 |    3 +--
 4 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/cpukit/posix/src/pbarrierwait.c b/cpukit/posix/src/pbarrierwait.c
index 036932e..1d7b981 100644
--- a/cpukit/posix/src/pbarrierwait.c
+++ b/cpukit/posix/src/pbarrierwait.c
@@ -40,6 +40,7 @@ int pthread_barrier_wait(
 {
   POSIX_Barrier_Control   *the_barrier = NULL;
   Objects_Locations        location;
+  Thread_Control          *executing;
 
   if ( !barrier )
     return EINVAL;
@@ -48,8 +49,10 @@ int pthread_barrier_wait(
   switch ( location ) {
 
     case OBJECTS_LOCAL:
+      executing = _Thread_Executing;
       _CORE_barrier_Wait(
         &the_barrier->Barrier,
+        executing,
         the_barrier->Object.id,
         true,
         0,
@@ -57,7 +60,7 @@ int pthread_barrier_wait(
       );
       _Objects_Put( &the_barrier->Object );
       return _POSIX_Barrier_Translate_core_barrier_return_code(
-                _Thread_Executing->Wait.return_code );
+                executing->Wait.return_code );
 
 #if defined(RTEMS_MULTIPROCESSING)
     case OBJECTS_REMOTE:
diff --git a/cpukit/rtems/src/barrierwait.c b/cpukit/rtems/src/barrierwait.c
index 515f935..a233908 100644
--- a/cpukit/rtems/src/barrierwait.c
+++ b/cpukit/rtems/src/barrierwait.c
@@ -32,13 +32,16 @@ rtems_status_code rtems_barrier_wait(
 {
   Barrier_Control   *the_barrier;
   Objects_Locations  location;
+  Thread_Control    *executing;
 
   the_barrier = _Barrier_Get( id, &location );
   switch ( location ) {
 
     case OBJECTS_LOCAL:
+      executing = _Thread_Executing;
       _CORE_barrier_Wait(
         &the_barrier->Barrier,
+        executing,
         id,
         true,
         timeout,
@@ -46,7 +49,7 @@ rtems_status_code rtems_barrier_wait(
       );
       _Objects_Put( &the_barrier->Object );
       return _Barrier_Translate_core_barrier_return_code(
-                _Thread_Executing->Wait.return_code );
+                executing->Wait.return_code );
 
 #if defined(RTEMS_MULTIPROCESSING)
     case OBJECTS_REMOTE:
diff --git a/cpukit/score/include/rtems/score/corebarrierimpl.h b/cpukit/score/include/rtems/score/corebarrierimpl.h
index cc22553..0353efb 100644
--- a/cpukit/score/include/rtems/score/corebarrierimpl.h
+++ b/cpukit/score/include/rtems/score/corebarrierimpl.h
@@ -92,6 +92,7 @@ void _CORE_barrier_Initialize(
  *  is released.
  *
  *  @param[in] the_barrier is the barrier to wait for
+ *  @param[in,out] executing The currently executing thread.
  *  @param[in] id is the id of the object being waited upon
  *  @param[in] wait is true if the calling thread is willing to wait
  *  @param[in] timeout is the number of ticks the calling thread is willing
@@ -103,6 +104,7 @@ void _CORE_barrier_Initialize(
  */
 void _CORE_barrier_Wait(
   CORE_barrier_Control                *the_barrier,
+  Thread_Control                      *executing,
   Objects_Id                           id,
   bool                                 wait,
   Watchdog_Interval                    timeout,
diff --git a/cpukit/score/src/corebarrierwait.c b/cpukit/score/src/corebarrierwait.c
index a5b685a..465402a 100644
--- a/cpukit/score/src/corebarrierwait.c
+++ b/cpukit/score/src/corebarrierwait.c
@@ -27,16 +27,15 @@
 
 void _CORE_barrier_Wait(
   CORE_barrier_Control                *the_barrier,
+  Thread_Control                      *executing,
   Objects_Id                           id,
   bool                                 wait,
   Watchdog_Interval                    timeout,
   CORE_barrier_API_mp_support_callout  api_barrier_mp_support
 )
 {
-  Thread_Control *executing;
   ISR_Level       level;
 
-  executing = _Thread_Executing;
   executing->Wait.return_code = CORE_BARRIER_STATUS_SUCCESSFUL;
   _ISR_Disable( level );
   the_barrier->number_of_waiting_threads++;




More information about the vc mailing list