1 | /* core_sem.h |
---|
2 | * |
---|
3 | * This include file contains all the constants and structures associated |
---|
4 | * with the Counting Semaphore Handler. A counting semaphore is the |
---|
5 | * standard Dijkstra binary semaphore used to provide synchronization |
---|
6 | * and mutual exclusion capabilities. |
---|
7 | * |
---|
8 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
9 | * On-Line Applications Research Corporation (OAR). |
---|
10 | * All rights assigned to U.S. Government, 1994. |
---|
11 | * |
---|
12 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
13 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
14 | * notice must appear in all copies of this file and its derivatives. |
---|
15 | * |
---|
16 | * $Id$ |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef __RTEMS_CORE_COUNTING_SEMAPHORE_h |
---|
20 | #define __RTEMS_CORE_COUNTING_SEMAPHORE_h |
---|
21 | |
---|
22 | #ifdef __cplusplus |
---|
23 | extern "C" { |
---|
24 | #endif |
---|
25 | |
---|
26 | #include <rtems/core/thread.h> |
---|
27 | #include <rtems/core/threadq.h> |
---|
28 | #include <rtems/core/priority.h> |
---|
29 | #include <rtems/core/watchdog.h> |
---|
30 | |
---|
31 | /* |
---|
32 | * The following type defines the callout which the API provides |
---|
33 | * to support global/multiprocessor operations on semaphores. |
---|
34 | */ |
---|
35 | |
---|
36 | typedef void ( *CORE_semaphore_API_mp_support_callout )( |
---|
37 | Thread_Control *, |
---|
38 | Objects_Id |
---|
39 | ); |
---|
40 | |
---|
41 | /* |
---|
42 | * Blocking disciplines for a semaphore. |
---|
43 | */ |
---|
44 | |
---|
45 | typedef enum { |
---|
46 | CORE_SEMAPHORE_DISCIPLINES_FIFO, |
---|
47 | CORE_SEMAPHORE_DISCIPLINES_PRIORITY |
---|
48 | } CORE_semaphore_Disciplines; |
---|
49 | |
---|
50 | /* |
---|
51 | * Core Semaphore handler return statuses. |
---|
52 | */ |
---|
53 | |
---|
54 | typedef enum { |
---|
55 | CORE_SEMAPHORE_STATUS_SUCCESSFUL, |
---|
56 | CORE_SEMAPHORE_STATUS_UNSATISFIED_NOWAIT, |
---|
57 | CORE_SEMAPHORE_WAS_DELETED, |
---|
58 | CORE_SEMAPHORE_TIMEOUT |
---|
59 | } CORE_semaphore_Status; |
---|
60 | |
---|
61 | /* |
---|
62 | * The following defines the control block used to manage the |
---|
63 | * attributes of each semaphore. |
---|
64 | */ |
---|
65 | |
---|
66 | typedef struct { |
---|
67 | CORE_semaphore_Disciplines discipline; |
---|
68 | } CORE_semaphore_Attributes; |
---|
69 | |
---|
70 | /* |
---|
71 | * The following defines the control block used to manage each |
---|
72 | * counting semaphore. |
---|
73 | */ |
---|
74 | |
---|
75 | typedef struct { |
---|
76 | Thread_queue_Control Wait_queue; |
---|
77 | CORE_semaphore_Attributes Attributes; |
---|
78 | unsigned32 count; |
---|
79 | } CORE_semaphore_Control; |
---|
80 | |
---|
81 | /* |
---|
82 | * _CORE_semaphore_Initialize |
---|
83 | * |
---|
84 | * DESCRIPTION: |
---|
85 | * |
---|
86 | * This routine initializes the semaphore based on the parameters passed. |
---|
87 | */ |
---|
88 | |
---|
89 | void _CORE_semaphore_Initialize( |
---|
90 | CORE_semaphore_Control *the_semaphore, |
---|
91 | Objects_Classes the_class, |
---|
92 | CORE_semaphore_Attributes *the_semaphore_attributes, |
---|
93 | unsigned32 initial_value, |
---|
94 | Thread_queue_Extract_callout proxy_extract_callout |
---|
95 | ); |
---|
96 | |
---|
97 | /* |
---|
98 | * _CORE_semaphore_Seize |
---|
99 | * |
---|
100 | * DESCRIPTION: |
---|
101 | * |
---|
102 | * This routine attempts to receive a unit from the_semaphore. |
---|
103 | * If a unit is available or if the wait flag is FALSE, then the routine |
---|
104 | * returns. Otherwise, the calling task is blocked until a unit becomes |
---|
105 | * available. |
---|
106 | */ |
---|
107 | |
---|
108 | void _CORE_semaphore_Seize( |
---|
109 | CORE_semaphore_Control *the_semaphore, |
---|
110 | Objects_Id id, |
---|
111 | boolean wait, |
---|
112 | Watchdog_Interval timeout |
---|
113 | ); |
---|
114 | |
---|
115 | /* |
---|
116 | * _CORE_semaphore_Surrender |
---|
117 | * |
---|
118 | * DESCRIPTION: |
---|
119 | * |
---|
120 | * This routine frees a unit to the semaphore. If a task was blocked waiting |
---|
121 | * for a unit from this semaphore, then that task will be readied and the unit |
---|
122 | * given to that task. Otherwise, the unit will be returned to the semaphore. |
---|
123 | */ |
---|
124 | |
---|
125 | CORE_semaphore_Status _CORE_semaphore_Surrender( |
---|
126 | CORE_semaphore_Control *the_semaphore, |
---|
127 | Objects_Id id, |
---|
128 | CORE_semaphore_API_mp_support_callout api_semaphore_mp_support |
---|
129 | ); |
---|
130 | |
---|
131 | /* |
---|
132 | * _CORE_semaphore_Flush |
---|
133 | * |
---|
134 | * DESCRIPTION: |
---|
135 | * |
---|
136 | * This routine assists in the deletion of a semaphore by flushing the |
---|
137 | * associated wait queue. |
---|
138 | */ |
---|
139 | |
---|
140 | void _CORE_semaphore_Flush( |
---|
141 | CORE_semaphore_Control *the_semaphore, |
---|
142 | Thread_queue_Flush_callout remote_extract_callout, |
---|
143 | unsigned32 status |
---|
144 | ); |
---|
145 | |
---|
146 | /* |
---|
147 | * _CORE_semaphore_Get_count |
---|
148 | * |
---|
149 | * DESCRIPTION: |
---|
150 | * |
---|
151 | * This routine returns the current count associated with the semaphore. |
---|
152 | */ |
---|
153 | |
---|
154 | STATIC INLINE unsigned32 _CORE_semaphore_Get_count( |
---|
155 | CORE_semaphore_Control *the_semaphore |
---|
156 | ); |
---|
157 | |
---|
158 | /* |
---|
159 | * _CORE_semaphore_Is_priority |
---|
160 | * |
---|
161 | * DESCRIPTION: |
---|
162 | * |
---|
163 | * This function returns TRUE if the priority attribute is |
---|
164 | * enabled in the attribute_set and FALSE otherwise. |
---|
165 | */ |
---|
166 | |
---|
167 | STATIC INLINE boolean _CORE_semaphore_Is_priority( |
---|
168 | CORE_semaphore_Attributes *the_attribute |
---|
169 | ); |
---|
170 | |
---|
171 | #include <rtems/core/coresem.inl> |
---|
172 | |
---|
173 | #ifdef __cplusplus |
---|
174 | } |
---|
175 | #endif |
---|
176 | |
---|
177 | #endif |
---|
178 | /* end of include file */ |
---|
179 | |
---|