diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-03-27 21:08:21 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2015-04-08 11:48:15 +0200 |
commit | edcf89b6f29b532360c2066446e4571286cbf705 (patch) | |
tree | 8f2a524a492df1b2f66a25fa8876296dbc26f049 /cpukit/rtems | |
parent | score: Return prev state in thread state set/clear (diff) | |
download | rtems-edcf89b6f29b532360c2066446e4571286cbf705.tar.bz2 |
rtems: Atomically suspend/resume tasks
Diffstat (limited to 'cpukit/rtems')
-rw-r--r-- | cpukit/rtems/src/taskresume.c | 11 | ||||
-rw-r--r-- | cpukit/rtems/src/tasksuspend.c | 11 |
2 files changed, 10 insertions, 12 deletions
diff --git a/cpukit/rtems/src/taskresume.c b/cpukit/rtems/src/taskresume.c index 86a22e195a..ed06a22e4a 100644 --- a/cpukit/rtems/src/taskresume.c +++ b/cpukit/rtems/src/taskresume.c @@ -27,18 +27,17 @@ rtems_status_code rtems_task_resume( { Thread_Control *the_thread; Objects_Locations location; + States_Control previous_state; the_thread = _Thread_Get( id, &location ); switch ( location ) { case OBJECTS_LOCAL: - if ( _States_Is_suspended( the_thread->current_state ) ) { - _Thread_Resume( the_thread ); - _Objects_Put( &the_thread->Object ); - return RTEMS_SUCCESSFUL; - } + previous_state = _Thread_Clear_state( the_thread, STATES_SUSPENDED ); _Objects_Put( &the_thread->Object ); - return RTEMS_INCORRECT_STATE; + + return _States_Is_suspended( previous_state ) ? + RTEMS_SUCCESSFUL : RTEMS_INCORRECT_STATE; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: diff --git a/cpukit/rtems/src/tasksuspend.c b/cpukit/rtems/src/tasksuspend.c index f8c43a73f1..ae7995a53c 100644 --- a/cpukit/rtems/src/tasksuspend.c +++ b/cpukit/rtems/src/tasksuspend.c @@ -27,18 +27,17 @@ rtems_status_code rtems_task_suspend( { Thread_Control *the_thread; Objects_Locations location; + States_Control previous_state; the_thread = _Thread_Get( id, &location ); switch ( location ) { case OBJECTS_LOCAL: - if ( !_States_Is_suspended( the_thread->current_state ) ) { - _Thread_Suspend( the_thread ); - _Objects_Put( &the_thread->Object ); - return RTEMS_SUCCESSFUL; - } + previous_state = _Thread_Set_state( the_thread, STATES_SUSPENDED ); _Objects_Put( &the_thread->Object ); - return RTEMS_ALREADY_SUSPENDED; + + return _States_Is_suspended( previous_state ) ? + RTEMS_ALREADY_SUSPENDED : RTEMS_SUCCESSFUL; #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: |