RTEMS  5.1
coresemimpl.h
Go to the documentation of this file.
1 
12 /*
13  * COPYRIGHT (c) 1989-2006.
14  * On-Line Applications Research Corporation (OAR).
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 #ifndef _RTEMS_SCORE_CORESEMIMPL_H
22 #define _RTEMS_SCORE_CORESEMIMPL_H
23 
24 #include <rtems/score/coresem.h>
25 #include <rtems/score/objectimpl.h>
27 #include <rtems/score/threadimpl.h>
29 #include <rtems/score/statesimpl.h>
30 #include <rtems/score/status.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
55  CORE_semaphore_Control *the_semaphore,
56  uint32_t initial_value
57 );
58 
68  CORE_semaphore_Control *the_semaphore,
69  Thread_queue_Context *queue_context
70 )
71 {
72  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, queue_context );
73 }
74 
84  CORE_semaphore_Control *the_semaphore,
85  Thread_queue_Context *queue_context
86 )
87 {
88  _Thread_queue_Release( &the_semaphore->Wait_queue, queue_context );
89 }
90 
101  CORE_semaphore_Control *the_semaphore,
102  const Thread_queue_Operations *operations,
103  Thread_queue_Context *queue_context
104 )
105 {
107  &the_semaphore->Wait_queue.Queue,
108  operations,
110  queue_context
111  );
112  _Thread_queue_Destroy( &the_semaphore->Wait_queue );
113 }
114 
132  CORE_semaphore_Control *the_semaphore,
133  const Thread_queue_Operations *operations,
134  uint32_t maximum_count,
135  Thread_queue_Context *queue_context
136 )
137 {
138  Thread_Control *the_thread;
139  Status_Control status;
140 
141  status = STATUS_SUCCESSFUL;
142 
143  _CORE_semaphore_Acquire_critical( the_semaphore, queue_context );
144 
145  the_thread = _Thread_queue_First_locked(
146  &the_semaphore->Wait_queue,
147  operations
148  );
149  if ( the_thread != NULL ) {
151  &the_semaphore->Wait_queue.Queue,
152  operations,
153  the_thread,
154  queue_context
155  );
156  } else {
157  if ( the_semaphore->count < maximum_count )
158  the_semaphore->count += 1;
159  else
160  status = STATUS_MAXIMUM_COUNT_EXCEEDED;
161 
162  _CORE_semaphore_Release( the_semaphore, queue_context );
163  }
164 
165  return status;
166 }
167 
176  const CORE_semaphore_Control *the_semaphore
177 )
178 {
179  return the_semaphore->count;
180 }
181 
203  CORE_semaphore_Control *the_semaphore,
204  const Thread_queue_Operations *operations,
205  Thread_Control *executing,
206  bool wait,
207  Thread_queue_Context *queue_context
208 )
209 {
210  _Assert( _ISR_Get_level() != 0 );
211 
212  _CORE_semaphore_Acquire_critical( the_semaphore, queue_context );
213  if ( the_semaphore->count != 0 ) {
214  the_semaphore->count -= 1;
215  _CORE_semaphore_Release( the_semaphore, queue_context );
216  return STATUS_SUCCESSFUL;
217  }
218 
219  if ( !wait ) {
220  _CORE_semaphore_Release( the_semaphore, queue_context );
221  return STATUS_UNSATISFIED;
222  }
223 
225  queue_context,
227  );
229  &the_semaphore->Wait_queue.Queue,
230  operations,
231  executing,
232  queue_context
233  );
234  return _Thread_Wait_get_status( executing );
235 }
236 
239 #ifdef __cplusplus
240 }
241 #endif
242 
243 #endif
244 /* end of include file */
RTEMS_INLINE_ROUTINE Status_Control _Thread_Wait_get_status(const Thread_Control *the_thread)
Get the status of the wait return code of the thread.
Definition: threadimpl.h:2328
void _CORE_semaphore_Initialize(CORE_semaphore_Control *the_semaphore, uint32_t initial_value)
Initializes the semaphore based on the parameters passed.
Definition: coresem.c:23
RTEMS_INLINE_ROUTINE Thread_Control * _Thread_queue_First_locked(Thread_queue_Control *the_thread_queue, const Thread_queue_Operations *operations)
Returns the first thread on the thread queue if it exists, otherwise NULL.
Definition: threadqimpl.h:1173
Thread queue context for the thread queue methods.
Definition: threadq.h:198
Definition: coresem.h:48
Constants and Structures Related with Thread Dispatch.
RTEMS_INLINE_ROUTINE void _CORE_semaphore_Acquire_critical(CORE_semaphore_Control *the_semaphore, Thread_queue_Context *queue_context)
Acquires the semaphore critical.
Definition: coresemimpl.h:67
#define STATES_WAITING_FOR_SEMAPHORE
Definition: statesimpl.h:51
RTEMS_INLINE_ROUTINE void _CORE_semaphore_Destroy(CORE_semaphore_Control *the_semaphore, const Thread_queue_Operations *operations, Thread_queue_Context *queue_context)
Destroys the semaphore.
Definition: coresemimpl.h:100
RTEMS_INLINE_ROUTINE Status_Control _CORE_semaphore_Surrender(CORE_semaphore_Control *the_semaphore, const Thread_queue_Operations *operations, uint32_t maximum_count, Thread_queue_Context *queue_context)
Surrenders a unit to the semaphore.
Definition: coresemimpl.h:131
#define _ISR_Get_level()
Return current interrupt level.
Definition: isrlevel.h:128
Thread queue operations.
Definition: threadq.h:517
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:583
Definition: thread.h:732
RTEMS_INLINE_ROUTINE void _Thread_queue_Destroy(Thread_queue_Control *the_thread_queue)
Destroys the thread queue.
Definition: threadqimpl.h:1378
size_t _Thread_queue_Flush_critical(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_queue_Flush_filter filter, Thread_queue_Context *queue_context)
Unblocks all threads enqueued on the thread queue.
Definition: threadqflush.c:63
RTEMS_INLINE_ROUTINE void _CORE_semaphore_Release(CORE_semaphore_Control *the_semaphore, Thread_queue_Context *queue_context)
Releases the semaphore.
Definition: coresemimpl.h:83
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_set_thread_state(Thread_queue_Context *queue_context, States_Control thread_state)
Sets the thread state for the thread to enqueue in the thread queue context.
Definition: threadqimpl.h:178
Constants and Structures Associated with the Manipulation of Objects.
Thread_Control * _Thread_queue_Flush_status_object_was_deleted(Thread_Control *the_thread, Thread_queue_Queue *queue, Thread_queue_Context *queue_context)
Status object was deleted thread queue flush filter function.
Definition: threadqflush.c:37
RTEMS_INLINE_ROUTINE uint32_t _CORE_semaphore_Get_count(const CORE_semaphore_Control *the_semaphore)
Returns the current count associated with the semaphore.
Definition: coresemimpl.h:175
Inlined Routines Associated with Thread State Information.
RTEMS_INLINE_ROUTINE void _Thread_queue_Acquire_critical(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Acquires the thread queue control in a critical section.
Definition: threadqimpl.h:681
Inlined Routines from the Thread Handler.
RTEMS_INLINE_ROUTINE void _Thread_queue_Release(Thread_queue_Control *the_thread_queue, Thread_queue_Context *queue_context)
Releases the thread queue control and enables interrupts.
Definition: threadqimpl.h:787
Inlined Routines in the Object Handler.
void _Thread_queue_Enqueue(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Blocks the thread and places it on the thread queue.
Definition: threadqenqueue.c:380
void _Thread_queue_Extract_critical(Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, Thread_queue_Context *queue_context)
Extracts the thread from the thread queue and unblocks it.
Definition: threadqenqueue.c:600
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:66
Thread_queue_Control Wait_queue
Definition: coresem.h:52
RTEMS_INLINE_ROUTINE Status_Control _CORE_semaphore_Seize(CORE_semaphore_Control *the_semaphore, const Thread_queue_Operations *operations, Thread_Control *executing, bool wait, Thread_queue_Context *queue_context)
Seizes the semaphore.
Definition: coresemimpl.h:202
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
Definition: assert.h:100
Data Associated with the Counting Semaphore Handler.
uint32_t count
Definition: coresem.h:55
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77