[c05d7502] | 1 | /** |
---|
| 2 | * @file |
---|
[0123e3b] | 3 | * |
---|
[c05d7502] | 4 | * @brief RTEMS Send Signal |
---|
| 5 | * @ingroup ClassicSignal |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | /* |
---|
[3a638ce] | 9 | * COPYRIGHT (c) 1989-2014. |
---|
[0123e3b] | 10 | * On-Line Applications Research Corporation (OAR). |
---|
| 11 | * |
---|
| 12 | * The license and distribution terms for this file may be |
---|
| 13 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 14 | * http://www.rtems.org/license/LICENSE. |
---|
[0123e3b] | 15 | */ |
---|
| 16 | |
---|
[1095ec1] | 17 | #if HAVE_CONFIG_H |
---|
| 18 | #include "config.h" |
---|
| 19 | #endif |
---|
| 20 | |
---|
[6cec745f] | 21 | #include <rtems/rtems/signalimpl.h> |
---|
[5618c37a] | 22 | #include <rtems/rtems/asrimpl.h> |
---|
[0123e3b] | 23 | #include <rtems/rtems/tasks.h> |
---|
[bb2ad039] | 24 | #include <rtems/score/threaddispatch.h> |
---|
[5618c37a] | 25 | #include <rtems/score/threadimpl.h> |
---|
[0123e3b] | 26 | |
---|
| 27 | rtems_status_code rtems_signal_send( |
---|
[d3b72ca3] | 28 | rtems_id id, |
---|
[69d2e69] | 29 | rtems_signal_set signal_set |
---|
[0123e3b] | 30 | ) |
---|
| 31 | { |
---|
[bb2ad039] | 32 | Thread_Control *the_thread; |
---|
| 33 | ISR_lock_Context lock_context; |
---|
| 34 | RTEMS_API_Control *api; |
---|
| 35 | ASR_Information *asr; |
---|
[0123e3b] | 36 | |
---|
[bb2ad039] | 37 | if ( signal_set == 0 ) { |
---|
[69d2e69] | 38 | return RTEMS_INVALID_NUMBER; |
---|
[bb2ad039] | 39 | } |
---|
[69d2e69] | 40 | |
---|
[e266d13] | 41 | the_thread = _Thread_Get( id, &lock_context ); |
---|
[ebe61382] | 42 | |
---|
[bb2ad039] | 43 | if ( the_thread == NULL ) { |
---|
[ebe61382] | 44 | #if defined(RTEMS_MULTIPROCESSING) |
---|
[bb2ad039] | 45 | return _Signal_MP_Send( id, signal_set ); |
---|
| 46 | #else |
---|
| 47 | return RTEMS_INVALID_ID; |
---|
[ebe61382] | 48 | #endif |
---|
[bb2ad039] | 49 | } |
---|
| 50 | |
---|
| 51 | api = the_thread->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 52 | asr = &api->Signal; |
---|
| 53 | |
---|
[105b4e6] | 54 | _Thread_State_acquire_critical( the_thread, &lock_context ); |
---|
[bb2ad039] | 55 | |
---|
| 56 | if ( _ASR_Is_null_handler( asr->handler ) ) { |
---|
[105b4e6] | 57 | _Thread_State_release( the_thread, &lock_context ); |
---|
[bb2ad039] | 58 | return RTEMS_NOT_DEFINED; |
---|
| 59 | } |
---|
[ebe61382] | 60 | |
---|
[bb2ad039] | 61 | if ( asr->is_enabled ) { |
---|
[6e4f929] | 62 | Per_CPU_Control *cpu_self; |
---|
| 63 | |
---|
[bb2ad039] | 64 | _ASR_Post_signals( signal_set, &asr->signals_posted ); |
---|
| 65 | _Thread_Add_post_switch_action( |
---|
| 66 | the_thread, |
---|
| 67 | &api->Signal_action, |
---|
| 68 | _Signal_Action_handler |
---|
| 69 | ); |
---|
[6e4f929] | 70 | cpu_self = _Thread_Dispatch_disable_critical( &lock_context ); |
---|
| 71 | _Thread_State_release( the_thread, &lock_context ); |
---|
| 72 | _Thread_Dispatch_enable( cpu_self ); |
---|
[bb2ad039] | 73 | } else { |
---|
| 74 | _ASR_Post_signals( signal_set, &asr->signals_pending ); |
---|
[105b4e6] | 75 | _Thread_State_release( the_thread, &lock_context ); |
---|
[0123e3b] | 76 | } |
---|
| 77 | |
---|
[bb2ad039] | 78 | return RTEMS_SUCCESSFUL; |
---|
[0123e3b] | 79 | } |
---|