1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief RTEMS Semaphore Release |
---|
5 | * @ingroup ClassicSem Semaphores |
---|
6 | * |
---|
7 | * DESCRIPTION: |
---|
8 | * |
---|
9 | * This package is the implementation of the Semaphore Manager. |
---|
10 | * This manager utilizes standard Dijkstra counting semaphores to provide |
---|
11 | * synchronization and mutual exclusion capabilities. |
---|
12 | * |
---|
13 | * Directives provided are: |
---|
14 | * |
---|
15 | * + create a semaphore |
---|
16 | * + get an ID of a semaphore |
---|
17 | * + delete a semaphore |
---|
18 | * + acquire a semaphore |
---|
19 | * + release a semaphore |
---|
20 | * |
---|
21 | */ |
---|
22 | |
---|
23 | /* |
---|
24 | * COPYRIGHT (c) 1989-2007. |
---|
25 | * On-Line Applications Research Corporation (OAR). |
---|
26 | * |
---|
27 | * The license and distribution terms for this file may be |
---|
28 | * found in the file LICENSE in this distribution or at |
---|
29 | * http://www.rtems.com/license/LICENSE. |
---|
30 | */ |
---|
31 | |
---|
32 | #if HAVE_CONFIG_H |
---|
33 | #include "config.h" |
---|
34 | #endif |
---|
35 | |
---|
36 | #include <rtems/system.h> |
---|
37 | #include <rtems/rtems/status.h> |
---|
38 | #include <rtems/rtems/support.h> |
---|
39 | #include <rtems/rtems/attr.h> |
---|
40 | #include <rtems/score/isr.h> |
---|
41 | #include <rtems/score/object.h> |
---|
42 | #include <rtems/rtems/options.h> |
---|
43 | #include <rtems/rtems/semimpl.h> |
---|
44 | #include <rtems/score/coremuteximpl.h> |
---|
45 | #include <rtems/score/coresemimpl.h> |
---|
46 | #include <rtems/score/states.h> |
---|
47 | #include <rtems/score/thread.h> |
---|
48 | #include <rtems/score/threadq.h> |
---|
49 | #if defined(RTEMS_MULTIPROCESSING) |
---|
50 | #include <rtems/score/mpci.h> |
---|
51 | #endif |
---|
52 | #include <rtems/score/sysstate.h> |
---|
53 | |
---|
54 | #include <rtems/score/interr.h> |
---|
55 | |
---|
56 | /* |
---|
57 | * rtems_semaphore_release |
---|
58 | * |
---|
59 | * This directive allows a thread to release a semaphore. |
---|
60 | * |
---|
61 | * Input parameters: |
---|
62 | * id - semaphore id |
---|
63 | * |
---|
64 | * Output parameters: |
---|
65 | * RTEMS_SUCCESSFUL - if successful |
---|
66 | * error code - if unsuccessful |
---|
67 | */ |
---|
68 | |
---|
69 | #if defined(RTEMS_MULTIPROCESSING) |
---|
70 | #define MUTEX_MP_SUPPORT _Semaphore_Core_mutex_mp_support |
---|
71 | #else |
---|
72 | #define MUTEX_MP_SUPPORT NULL |
---|
73 | #endif |
---|
74 | |
---|
75 | rtems_status_code rtems_semaphore_release( |
---|
76 | rtems_id id |
---|
77 | ) |
---|
78 | { |
---|
79 | register Semaphore_Control *the_semaphore; |
---|
80 | Objects_Locations location; |
---|
81 | CORE_mutex_Status mutex_status; |
---|
82 | CORE_semaphore_Status semaphore_status; |
---|
83 | |
---|
84 | the_semaphore = _Semaphore_Get( id, &location ); |
---|
85 | switch ( location ) { |
---|
86 | |
---|
87 | case OBJECTS_LOCAL: |
---|
88 | if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) { |
---|
89 | mutex_status = _CORE_mutex_Surrender( |
---|
90 | &the_semaphore->Core_control.mutex, |
---|
91 | id, |
---|
92 | MUTEX_MP_SUPPORT |
---|
93 | ); |
---|
94 | _Objects_Put( &the_semaphore->Object ); |
---|
95 | return _Semaphore_Translate_core_mutex_return_code( mutex_status ); |
---|
96 | } else { |
---|
97 | semaphore_status = _CORE_semaphore_Surrender( |
---|
98 | &the_semaphore->Core_control.semaphore, |
---|
99 | id, |
---|
100 | MUTEX_MP_SUPPORT |
---|
101 | ); |
---|
102 | _Objects_Put( &the_semaphore->Object ); |
---|
103 | return |
---|
104 | _Semaphore_Translate_core_semaphore_return_code( semaphore_status ); |
---|
105 | } |
---|
106 | |
---|
107 | #if defined(RTEMS_MULTIPROCESSING) |
---|
108 | case OBJECTS_REMOTE: |
---|
109 | return _Semaphore_MP_Send_request_packet( |
---|
110 | SEMAPHORE_MP_RELEASE_REQUEST, |
---|
111 | id, |
---|
112 | 0, /* Not used */ |
---|
113 | MPCI_DEFAULT_TIMEOUT |
---|
114 | ); |
---|
115 | #endif |
---|
116 | |
---|
117 | case OBJECTS_ERROR: |
---|
118 | break; |
---|
119 | } |
---|
120 | |
---|
121 | return RTEMS_INVALID_ID; |
---|
122 | } |
---|