1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Semaphore Flush |
---|
5 | * @ingroup ClassicSem |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2014. |
---|
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 |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/rtems/semimpl.h> |
---|
22 | |
---|
23 | rtems_status_code rtems_semaphore_flush( rtems_id id ) |
---|
24 | { |
---|
25 | Semaphore_Control *the_semaphore; |
---|
26 | Thread_queue_Context queue_context; |
---|
27 | |
---|
28 | the_semaphore = _Semaphore_Get( id, &queue_context ); |
---|
29 | |
---|
30 | if ( the_semaphore == NULL ) { |
---|
31 | #if defined(RTEMS_MULTIPROCESSING) |
---|
32 | if ( _Semaphore_MP_Is_remote( id ) ) { |
---|
33 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
34 | } |
---|
35 | #endif |
---|
36 | |
---|
37 | return RTEMS_INVALID_ID; |
---|
38 | } |
---|
39 | |
---|
40 | _Thread_queue_Acquire_critical( |
---|
41 | &the_semaphore->Core_control.Wait_queue, |
---|
42 | &queue_context.Lock_context |
---|
43 | ); |
---|
44 | _Thread_queue_Context_set_MP_callout( |
---|
45 | &queue_context, |
---|
46 | _Semaphore_MP_Send_object_was_deleted |
---|
47 | ); |
---|
48 | |
---|
49 | switch ( the_semaphore->variant ) { |
---|
50 | #if defined(RTEMS_SMP) |
---|
51 | case SEMAPHORE_VARIANT_MRSP: |
---|
52 | _Thread_queue_Release( |
---|
53 | &the_semaphore->Core_control.Wait_queue, |
---|
54 | &queue_context.Lock_context |
---|
55 | ); |
---|
56 | return RTEMS_NOT_DEFINED; |
---|
57 | #endif |
---|
58 | default: |
---|
59 | _Assert( |
---|
60 | the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX |
---|
61 | || the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING |
---|
62 | || the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL |
---|
63 | || the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY |
---|
64 | || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING |
---|
65 | ); |
---|
66 | _Thread_queue_Flush_critical( |
---|
67 | &the_semaphore->Core_control.Wait_queue.Queue, |
---|
68 | _Semaphore_Get_operations( the_semaphore ), |
---|
69 | _Thread_queue_Flush_status_unavailable, |
---|
70 | &queue_context |
---|
71 | ); |
---|
72 | break; |
---|
73 | } |
---|
74 | |
---|
75 | return RTEMS_SUCCESSFUL; |
---|
76 | } |
---|