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 | #include <rtems/rtems/attrimpl.h> |
---|
23 | |
---|
24 | rtems_status_code rtems_semaphore_flush( rtems_id id ) |
---|
25 | { |
---|
26 | Semaphore_Control *the_semaphore; |
---|
27 | ISR_lock_Context lock_context; |
---|
28 | rtems_attribute attribute_set; |
---|
29 | |
---|
30 | the_semaphore = _Semaphore_Get_interrupt_disable( id, &lock_context ); |
---|
31 | |
---|
32 | if ( the_semaphore == NULL ) { |
---|
33 | #if defined(RTEMS_MULTIPROCESSING) |
---|
34 | if ( _Semaphore_MP_Is_remote( id ) ) { |
---|
35 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
36 | } |
---|
37 | #endif |
---|
38 | |
---|
39 | return RTEMS_INVALID_ID; |
---|
40 | } |
---|
41 | |
---|
42 | attribute_set = the_semaphore->attribute_set; |
---|
43 | |
---|
44 | #if defined(RTEMS_SMP) |
---|
45 | if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) { |
---|
46 | _ISR_lock_ISR_enable( &lock_context ); |
---|
47 | return RTEMS_NOT_DEFINED; |
---|
48 | } else |
---|
49 | #endif |
---|
50 | if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) { |
---|
51 | _CORE_mutex_Acquire_critical( |
---|
52 | &the_semaphore->Core_control.mutex, |
---|
53 | &lock_context |
---|
54 | ); |
---|
55 | _CORE_mutex_Flush( |
---|
56 | &the_semaphore->Core_control.mutex, |
---|
57 | _CORE_mutex_Unsatisfied_nowait, |
---|
58 | _Semaphore_MP_Send_object_was_deleted, |
---|
59 | id, |
---|
60 | &lock_context |
---|
61 | ); |
---|
62 | } else { |
---|
63 | _CORE_semaphore_Acquire_critical( |
---|
64 | &the_semaphore->Core_control.semaphore, |
---|
65 | &lock_context |
---|
66 | ); |
---|
67 | _CORE_semaphore_Flush( |
---|
68 | &the_semaphore->Core_control.semaphore, |
---|
69 | _Semaphore_MP_Send_object_was_deleted, |
---|
70 | id, |
---|
71 | &lock_context |
---|
72 | ); |
---|
73 | } |
---|
74 | return RTEMS_SUCCESSFUL; |
---|
75 | } |
---|