1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSImplClassicSemaphore |
---|
5 | * |
---|
6 | * @brief This source file contains the implementation of |
---|
7 | * rtems_semaphore_flush(). |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2014. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifdef HAVE_CONFIG_H |
---|
20 | #include "config.h" |
---|
21 | #endif |
---|
22 | |
---|
23 | #include <rtems/rtems/semimpl.h> |
---|
24 | |
---|
25 | rtems_status_code rtems_semaphore_flush( rtems_id id ) |
---|
26 | { |
---|
27 | Semaphore_Control *the_semaphore; |
---|
28 | Thread_queue_Context queue_context; |
---|
29 | uintptr_t flags; |
---|
30 | Semaphore_Variant variant; |
---|
31 | |
---|
32 | the_semaphore = _Semaphore_Get( id, &queue_context ); |
---|
33 | |
---|
34 | if ( the_semaphore == NULL ) { |
---|
35 | #if defined(RTEMS_MULTIPROCESSING) |
---|
36 | if ( _Semaphore_MP_Is_remote( id ) ) { |
---|
37 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
38 | } |
---|
39 | #endif |
---|
40 | |
---|
41 | return RTEMS_INVALID_ID; |
---|
42 | } |
---|
43 | |
---|
44 | _Thread_queue_Acquire_critical( |
---|
45 | &the_semaphore->Core_control.Wait_queue, |
---|
46 | &queue_context |
---|
47 | ); |
---|
48 | _Thread_queue_Context_set_MP_callout( |
---|
49 | &queue_context, |
---|
50 | _Semaphore_MP_Send_object_was_deleted |
---|
51 | ); |
---|
52 | flags = _Semaphore_Get_flags( the_semaphore ); |
---|
53 | variant = _Semaphore_Get_variant( flags ); |
---|
54 | |
---|
55 | switch ( variant ) { |
---|
56 | #if defined(RTEMS_SMP) |
---|
57 | case SEMAPHORE_VARIANT_MRSP: |
---|
58 | _Thread_queue_Release( |
---|
59 | &the_semaphore->Core_control.Wait_queue, |
---|
60 | &queue_context |
---|
61 | ); |
---|
62 | return RTEMS_NOT_DEFINED; |
---|
63 | #endif |
---|
64 | default: |
---|
65 | _Assert( |
---|
66 | variant == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY |
---|
67 | || variant == SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING |
---|
68 | || variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL |
---|
69 | || variant == SEMAPHORE_VARIANT_SIMPLE_BINARY |
---|
70 | || variant == SEMAPHORE_VARIANT_COUNTING |
---|
71 | ); |
---|
72 | _Thread_queue_Flush_critical( |
---|
73 | &the_semaphore->Core_control.Wait_queue.Queue, |
---|
74 | _Semaphore_Get_operations( flags ), |
---|
75 | _Thread_queue_Flush_status_unavailable, |
---|
76 | &queue_context |
---|
77 | ); |
---|
78 | break; |
---|
79 | } |
---|
80 | |
---|
81 | return RTEMS_SUCCESSFUL; |
---|
82 | } |
---|