[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:    e36f2b8c914b73bacfc89b997f4a59d5387303ce
Changeset: http://git.rtems.org/rtems/commit/?id=e36f2b8c914b73bacfc89b997f4a59d5387303ce

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Thu Jul 18 14:27:30 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/semaphorewaitsupp.c           |    7 +++++--
 cpukit/rtems/src/semobtain.c                   |    1 +
 cpukit/score/include/rtems/score/coresemimpl.h |    7 ++++---
 cpukit/score/src/coresemseize.c                |    3 +--
 cpukit/score/src/mpci.c                        |   10 ++++++++--
 5 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/cpukit/posix/src/semaphorewaitsupp.c b/cpukit/posix/src/semaphorewaitsupp.c
index 67ecb43..a590537 100644
--- a/cpukit/posix/src/semaphorewaitsupp.c
+++ b/cpukit/posix/src/semaphorewaitsupp.c
@@ -40,25 +40,28 @@ int _POSIX_Semaphore_Wait_support(
 {
   POSIX_Semaphore_Control *the_semaphore;
   Objects_Locations        location;
+  Thread_Control          *executing;
 
   the_semaphore = _POSIX_Semaphore_Get( sem, &location );
   switch ( location ) {
 
     case OBJECTS_LOCAL:
+      executing = _Thread_Executing;
       _CORE_semaphore_Seize(
         &the_semaphore->Semaphore,
+        executing,
         the_semaphore->Object.id,
         blocking,
         timeout
       );
       _Objects_Put( &the_semaphore->Object );
 
-      if ( !_Thread_Executing->Wait.return_code )
+      if ( !executing->Wait.return_code )
         return 0;
 
       rtems_set_errno_and_return_minus_one(
         _POSIX_Semaphore_Translate_core_semaphore_return_code(
-          _Thread_Executing->Wait.return_code
+          executing->Wait.return_code
         )
       );
 
diff --git a/cpukit/rtems/src/semobtain.c b/cpukit/rtems/src/semobtain.c
index 89e7bb6..f29b9b5 100644
--- a/cpukit/rtems/src/semobtain.c
+++ b/cpukit/rtems/src/semobtain.c
@@ -71,6 +71,7 @@ rtems_status_code rtems_semaphore_obtain(
       /* must be a counting semaphore */
       _CORE_semaphore_Seize_isr_disable(
         &the_semaphore->Core_control.semaphore,
+        executing,
         id,
         ((_Options_Is_no_wait( option_set )) ? false : true),
         timeout,
diff --git a/cpukit/score/include/rtems/score/coresemimpl.h b/cpukit/score/include/rtems/score/coresemimpl.h
index 62c1c2a..35fbce5 100644
--- a/cpukit/score/include/rtems/score/coresemimpl.h
+++ b/cpukit/score/include/rtems/score/coresemimpl.h
@@ -108,6 +108,7 @@ void _CORE_semaphore_Initialize(
    *  available.
    *
    *  @param[in] the_semaphore is the semaphore to seize
+   *  @param[in,out] executing The currently executing thread.
    *  @param[in] id is the Id of the API level Semaphore object associated
    *         with this instance of a SuperCore Semaphore
    *  @param[in] wait indicates if the caller is willing to block
@@ -116,6 +117,7 @@ void _CORE_semaphore_Initialize(
    */
   void _CORE_semaphore_Seize(
     CORE_semaphore_Control  *the_semaphore,
+    Thread_Control          *executing,
     Objects_Id               id,
     bool                     wait,
     Watchdog_Interval        timeout
@@ -201,6 +203,7 @@ RTEMS_INLINE_ROUTINE uint32_t  _CORE_semaphore_Get_count(
  * available.
  *
  * @param[in] the_semaphore is the semaphore to obtain
+ * @param[in,out] executing The currently executing thread.
  * @param[in] id is the Id of the owning API level Semaphore object
  * @param[in] wait is true if the thread is willing to wait
  * @param[in] timeout is the maximum number of ticks to block
@@ -211,17 +214,15 @@ RTEMS_INLINE_ROUTINE uint32_t  _CORE_semaphore_Get_count(
  */
 RTEMS_INLINE_ROUTINE void _CORE_semaphore_Seize_isr_disable(
   CORE_semaphore_Control  *the_semaphore,
+  Thread_Control          *executing,
   Objects_Id               id,
   bool                     wait,
   Watchdog_Interval        timeout,
   ISR_Level                level
 )
 {
-  Thread_Control *executing;
-
   /* disabled when you get here */
 
-  executing = _Thread_Executing;
   executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
   if ( the_semaphore->count != 0 ) {
     the_semaphore->count -= 1;
diff --git a/cpukit/score/src/coresemseize.c b/cpukit/score/src/coresemseize.c
index 7ad2317..8da9ca3 100644
--- a/cpukit/score/src/coresemseize.c
+++ b/cpukit/score/src/coresemseize.c
@@ -30,15 +30,14 @@
 
 void _CORE_semaphore_Seize(
   CORE_semaphore_Control *the_semaphore,
+  Thread_Control         *executing,
   Objects_Id              id,
   bool                    wait,
   Watchdog_Interval       timeout
 )
 {
-  Thread_Control *executing;
   ISR_Level       level;
 
-  executing = _Thread_Executing;
   executing->Wait.return_code = CORE_SEMAPHORE_STATUS_SUCCESSFUL;
   _ISR_Disable( level );
   if ( the_semaphore->count != 0 ) {
diff --git a/cpukit/score/src/mpci.c b/cpukit/score/src/mpci.c
index e4c43b7..9ba6106 100644
--- a/cpukit/score/src/mpci.c
+++ b/cpukit/score/src/mpci.c
@@ -289,14 +289,20 @@ Thread _MPCI_Receive_server(
   MPCI_Packet_processor     the_function;
   Thread_Control           *executing;
 
-  executing = _Thread_Executing;
+  executing = _Thread_Get_executing();
 
   for ( ; ; ) {
 
     executing->receive_packet = NULL;
 
     _Thread_Disable_dispatch();
-    _CORE_semaphore_Seize( &_MPCI_Semaphore, 0, true, WATCHDOG_NO_TIMEOUT );
+    _CORE_semaphore_Seize(
+      &_MPCI_Semaphore,
+      executing,
+      0,
+      true,
+      WATCHDOG_NO_TIMEOUT
+    );
     _Thread_Enable_dispatch();
 
     for ( ; ; ) {




More information about the vc mailing list