RTEMS  5.0.0
coresemimpl.h
Go to the documentation of this file.
1 
10 /*
11  * COPYRIGHT (c) 1989-2006.
12  * On-Line Applications Research Corporation (OAR).
13  *
14  * The license and distribution terms for this file may be
15  * found in the file LICENSE in this distribution or at
16  * http://www.rtems.org/license/LICENSE.
17  */
18 
19 #ifndef _RTEMS_SCORE_CORESEMIMPL_H
20 #define _RTEMS_SCORE_CORESEMIMPL_H
21 
22 #include <rtems/score/coresem.h>
23 #include <rtems/score/objectimpl.h>
24 #include <rtems/score/threaddispatch.h>
25 #include <rtems/score/threadimpl.h>
27 #include <rtems/score/statesimpl.h>
28 #include <rtems/score/status.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
52  CORE_semaphore_Control *the_semaphore,
53  uint32_t initial_value
54 );
55 
56 RTEMS_INLINE_ROUTINE void _CORE_semaphore_Acquire_critical(
57  CORE_semaphore_Control *the_semaphore,
58  Thread_queue_Context *queue_context
59 )
60 {
61  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, queue_context );
62 }
63 
64 RTEMS_INLINE_ROUTINE void _CORE_semaphore_Release(
65  CORE_semaphore_Control *the_semaphore,
66  Thread_queue_Context *queue_context
67 )
68 {
69  _Thread_queue_Release( &the_semaphore->Wait_queue, queue_context );
70 }
71 
72 RTEMS_INLINE_ROUTINE void _CORE_semaphore_Destroy(
73  CORE_semaphore_Control *the_semaphore,
74  const Thread_queue_Operations *operations,
75  Thread_queue_Context *queue_context
76 )
77 {
79  &the_semaphore->Wait_queue.Queue,
80  operations,
82  queue_context
83  );
84  _Thread_queue_Destroy( &the_semaphore->Wait_queue );
85 }
86 
102  CORE_semaphore_Control *the_semaphore,
103  const Thread_queue_Operations *operations,
104  uint32_t maximum_count,
105  Thread_queue_Context *queue_context
106 )
107 {
108  Thread_Control *the_thread;
109  Status_Control status;
110 
111  status = STATUS_SUCCESSFUL;
112 
113  _CORE_semaphore_Acquire_critical( the_semaphore, queue_context );
114 
115  the_thread = _Thread_queue_First_locked(
116  &the_semaphore->Wait_queue,
117  operations
118  );
119  if ( the_thread != NULL ) {
121  &the_semaphore->Wait_queue.Queue,
122  operations,
123  the_thread,
124  queue_context
125  );
126  } else {
127  if ( the_semaphore->count < maximum_count )
128  the_semaphore->count += 1;
129  else
130  status = STATUS_MAXIMUM_COUNT_EXCEEDED;
131 
132  _CORE_semaphore_Release( the_semaphore, queue_context );
133  }
134 
135  return status;
136 }
137 
146  const CORE_semaphore_Control *the_semaphore
147 )
148 {
149  return the_semaphore->count;
150 }
151 
166  CORE_semaphore_Control *the_semaphore,
167  const Thread_queue_Operations *operations,
168  Thread_Control *executing,
169  bool wait,
170  Thread_queue_Context *queue_context
171 )
172 {
173  _Assert( _ISR_Get_level() != 0 );
174 
175  _CORE_semaphore_Acquire_critical( the_semaphore, queue_context );
176  if ( the_semaphore->count != 0 ) {
177  the_semaphore->count -= 1;
178  _CORE_semaphore_Release( the_semaphore, queue_context );
179  return STATUS_SUCCESSFUL;
180  }
181 
182  if ( !wait ) {
183  _CORE_semaphore_Release( the_semaphore, queue_context );
184  return STATUS_UNSATISFIED;
185  }
186 
188  queue_context,
190  );
192  &the_semaphore->Wait_queue.Queue,
193  operations,
194  executing,
195  queue_context
196  );
197  return _Thread_Wait_get_status( executing );
198 }
199 
202 #ifdef __cplusplus
203 }
204 #endif
205 
206 #endif
207 /* end of include file */
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:971
Thread queue context for the thread queue methods.
Definition: threadq.h:193
#define RTEMS_INLINE_ROUTINE
Definition: basedefs.h:65
Definition: coresem.h:44
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)
Definition: coresemimpl.h:165
RTEMS_INLINE_ROUTINE uint32_t _CORE_semaphore_Get_count(const CORE_semaphore_Control *the_semaphore)
Definition: coresemimpl.h:145
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:36
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:379
#define _ISR_Get_level()
Return current interrupt level.
Definition: isrlevel.h:125
void _CORE_semaphore_Initialize(CORE_semaphore_Control *the_semaphore, uint32_t initial_value)
Initialize the semaphore based on the parameters passed.
Definition: coresem.c:23
Thread queue operations.
Definition: threadq.h:512
Thread_queue_Queue Queue
The actual thread queue.
Definition: threadq.h:578
Definition: thread.h:728
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)
Surrender a unit to a semaphore.
Definition: coresemimpl.h:101
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:62
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:599
Inlined Routines Associated with Thread State Information.
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:134
Inlined Routines from the Thread Handler.
#define STATES_WAITING_FOR_SEMAPHORE
Definition: statesimpl.h:48
Inlined Routines in the Object Handler.
Thread_queue_Control Wait_queue
Definition: coresem.h:48
Data Associated with the Counting Semaphore Handler.
uint32_t count
Definition: coresem.h:51
#define NULL
Requests a GPIO pin group configuration.
Definition: bestcomm_api.h:77