summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2015-03-01 13:50:55 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2015-03-05 11:36:44 +0100
commit5b393fa5b52f2fc2f8f7e0688df86f8b80ab3331 (patch)
tree7fed701117eb2d0ac6d534631743f2e371c1982f
parentscore: Add ISR lock to Objects_Control (diff)
downloadrtems-5b393fa5b52f2fc2f8f7e0688df86f8b80ab3331.tar.bz2
score: Add thread acquire
Update #2273.
-rw-r--r--cpukit/score/include/rtems/score/threadimpl.h18
-rw-r--r--cpukit/score/src/threadget.c85
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 e5e51ec322..19c22bcc46 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 d95a7ebd7d..1091333059 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 );
+}