1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Semaphore Flush |
---|
5 | * @ingroup ClassicSem |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
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.com/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/system.h> |
---|
22 | #include <rtems/rtems/status.h> |
---|
23 | #include <rtems/rtems/support.h> |
---|
24 | #include <rtems/rtems/attr.h> |
---|
25 | #include <rtems/score/isr.h> |
---|
26 | #include <rtems/score/object.h> |
---|
27 | #include <rtems/rtems/options.h> |
---|
28 | #include <rtems/rtems/sem.h> |
---|
29 | #include <rtems/score/coremutex.h> |
---|
30 | #include <rtems/score/coresem.h> |
---|
31 | #include <rtems/score/states.h> |
---|
32 | #include <rtems/score/thread.h> |
---|
33 | #include <rtems/score/threadq.h> |
---|
34 | #if defined(RTEMS_MULTIPROCESSING) |
---|
35 | #include <rtems/score/mpci.h> |
---|
36 | #endif |
---|
37 | #include <rtems/score/sysstate.h> |
---|
38 | |
---|
39 | #include <rtems/score/interr.h> |
---|
40 | |
---|
41 | #if defined(RTEMS_MULTIPROCESSING) |
---|
42 | #define SEND_OBJECT_WAS_DELETED _Semaphore_MP_Send_object_was_deleted |
---|
43 | #else |
---|
44 | #define SEND_OBJECT_WAS_DELETED NULL |
---|
45 | #endif |
---|
46 | |
---|
47 | rtems_status_code rtems_semaphore_flush( |
---|
48 | rtems_id id |
---|
49 | ) |
---|
50 | { |
---|
51 | register Semaphore_Control *the_semaphore; |
---|
52 | Objects_Locations location; |
---|
53 | |
---|
54 | the_semaphore = _Semaphore_Get( id, &location ); |
---|
55 | switch ( location ) { |
---|
56 | |
---|
57 | case OBJECTS_LOCAL: |
---|
58 | if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) { |
---|
59 | _CORE_mutex_Flush( |
---|
60 | &the_semaphore->Core_control.mutex, |
---|
61 | SEND_OBJECT_WAS_DELETED, |
---|
62 | CORE_MUTEX_STATUS_UNSATISFIED_NOWAIT |
---|
63 | ); |
---|
64 | } else { |
---|
65 | _CORE_semaphore_Flush( |
---|
66 | &the_semaphore->Core_control.semaphore, |
---|
67 | SEND_OBJECT_WAS_DELETED, |
---|
68 | CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT |
---|
69 | ); |
---|
70 | } |
---|
71 | _Objects_Put( &the_semaphore->Object ); |
---|
72 | return RTEMS_SUCCESSFUL; |
---|
73 | |
---|
74 | #if defined(RTEMS_MULTIPROCESSING) |
---|
75 | case OBJECTS_REMOTE: |
---|
76 | _Thread_Dispatch(); |
---|
77 | return RTEMS_ILLEGAL_ON_REMOTE_OBJECT; |
---|
78 | #endif |
---|
79 | |
---|
80 | case OBJECTS_ERROR: |
---|
81 | break; |
---|
82 | } |
---|
83 | |
---|
84 | return RTEMS_INVALID_ID; |
---|
85 | } |
---|