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