From 5b393fa5b52f2fc2f8f7e0688df86f8b80ab3331 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Sun, 1 Mar 2015 13:50:55 +0100 Subject: 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 e5e51ec322..19c22bcc46 100644 --- a/cpukit/score/include/rtems/score/threadimpl.h +++ b/cpukit/score/include/rtems/score/threadimpl.h @@ -397,6 +397,24 @@ Thread_Control *_Thread_Get ( Objects_Locations *location ); +/** + * @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. * 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 -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 ); +} -- cgit v1.2.3