[rtems commit] score: Add thread acquire

Sebastian Huber sebh at rtems.org
Fri Mar 6 10:24:40 UTC 2015


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Sun Mar  1 13:50:55 2015 +0100

score: Add thread acquire

Update #2273.

---

 cpukit/score/include/rtems/score/threadimpl.h | 18 ++++++
 cpukit/score/src/threadget.c                  | 85 +++++++++++++++++++--------
 2 files changed, 79 insertions(+), 24 deletions(-)

diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index e5e51ec..19c22bc 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -398,6 +398,24 @@ Thread_Control *_Thread_Get (
 );
 
 /**
+ * @brief Acquires a thread by its identifier.
+ *
+ * @see _Objects_Acquire().
+ */
+Thread_Control *_Thread_Acquire(
+  Objects_Id         id,
+  Objects_Locations *location,
+  ISR_lock_Context  *lock_context
+);
+
+/**
+ * @brief Acquires the executing thread.
+ *
+ * @see _Objects_Acquire().
+ */
+Thread_Control *_Thread_Acquire_executing( ISR_lock_Context *lock_context );
+
+/**
  *  @brief Cancel a blocking operation due to ISR.
  *
  *  This method is used to cancel a blocking operation that was
diff --git a/cpukit/score/src/threadget.c b/cpukit/score/src/threadget.c
index d95a7eb..1091333 100644
--- a/cpukit/score/src/threadget.c
+++ b/cpukit/score/src/threadget.c
@@ -21,34 +21,22 @@
 
 #include <rtems/score/threadimpl.h>
 
-Thread_Control *_Thread_Get (
-  Objects_Id         id,
-  Objects_Locations *location
+static Objects_Information *_Thread_Get_objects_information(
+  Objects_Id id
 )
 {
   uint32_t             the_api;
   uint32_t             the_class;
   Objects_Information **api_information;
-  Objects_Information *information;
-  Thread_Control      *tp = (Thread_Control *) 0;
-
-  if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
-    _Thread_Disable_dispatch();
-    *location = OBJECTS_LOCAL;
-    tp = _Thread_Executing;
-    goto done;
-  }
 
   the_api = _Objects_Get_API( id );
   if ( !_Objects_Is_api_valid( the_api ) ) {
-    *location = OBJECTS_ERROR;
-    goto done;
+    return NULL;
   }
 
   the_class = _Objects_Get_class( id );
   if ( the_class != 1 ) {       /* threads are always first class :) */
-    *location = OBJECTS_ERROR;
-    goto done;
+    return NULL;
   }
 
   api_information = _Objects_Information_table[ the_api ];
@@ -59,19 +47,68 @@ Thread_Control *_Thread_Get (
    *  on in all configurations.
    */
   if ( !api_information ) {
-    *location = OBJECTS_ERROR;
-    goto done;
+    return NULL;
+  }
+
+  return api_information[ the_class ];
+}
+
+Thread_Control *_Thread_Get(
+  Objects_Id         id,
+  Objects_Locations *location
+)
+{
+  Objects_Information *information;
+
+  if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
+    _Thread_Disable_dispatch();
+    *location = OBJECTS_LOCAL;
+    return _Thread_Executing;
   }
 
-  information = api_information[ the_class ];
-  if ( !information ) {
+  information = _Thread_Get_objects_information( id );
+  if ( information == NULL ) {
     *location = OBJECTS_ERROR;
-    goto done;
+    return NULL;
   }
 
-  tp = (Thread_Control *) _Objects_Get( information, id, location );
+  return (Thread_Control *) _Objects_Get( information, id, location );
+}
+
+Thread_Control *_Thread_Acquire_executing( ISR_lock_Context *lock_context )
+{
+  Thread_Control *executing;
 
-done:
-  return tp;
+#if defined(RTEMS_SMP)
+  _ISR_Disable_without_giant( lock_context->Lock_context.isr_level );
+#else
+  _ISR_Disable( lock_context->isr_level );
+#endif
+  executing = _Thread_Executing;
+  _ISR_lock_Acquire( &executing->Object.Lock, lock_context );
+
+  return executing;
 }
 
+Thread_Control *_Thread_Acquire(
+  Objects_Id         id,
+  Objects_Locations *location,
+  ISR_lock_Context  *lock_context
+)
+{
+  Objects_Information *information;
+
+  if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
+    *location = OBJECTS_LOCAL;
+    return _Thread_Acquire_executing( lock_context );
+  }
+
+  information = _Thread_Get_objects_information( id );
+  if ( information == NULL ) {
+    *location = OBJECTS_ERROR;
+    return NULL;
+  }
+
+  return (Thread_Control *)
+    _Objects_Acquire( information, id, location, lock_context );
+}



More information about the vc mailing list