RTEMS CPU Kit with SuperCore  4.11.2
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>
26 #include <rtems/score/statesimpl.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
40 typedef enum {
62 
68 #define CORE_SEMAPHORE_STATUS_LAST CORE_SEMAPHORE_MAXIMUM_COUNT_EXCEEDED
69 
77  );
78 
93  CORE_semaphore_Control *the_semaphore,
94  const CORE_semaphore_Attributes *the_semaphore_attributes,
95  uint32_t initial_value
96 );
97 
98 RTEMS_INLINE_ROUTINE void _CORE_semaphore_Destroy(
99  CORE_semaphore_Control *the_semaphore
100 )
101 {
102  _Thread_queue_Destroy( &the_semaphore->Wait_queue );
103 }
104 
123  CORE_semaphore_Control *the_semaphore,
124  Objects_Id id,
125  CORE_semaphore_API_mp_support_callout api_semaphore_mp_support,
126  ISR_lock_Context *lock_context
127 )
128 {
129  Thread_Control *the_thread;
130  CORE_semaphore_Status status;
131 
133 
134  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
135 
136  the_thread = _Thread_queue_First_locked( &the_semaphore->Wait_queue );
137  if ( the_thread != NULL ) {
138 #if defined(RTEMS_MULTIPROCESSING)
140 #endif
141 
143  &the_semaphore->Wait_queue,
144  the_thread,
145  lock_context
146  );
147 
148 #if defined(RTEMS_MULTIPROCESSING)
149  if ( !_Objects_Is_local_id( the_thread->Object.id ) )
150  (*api_semaphore_mp_support) ( the_thread, id );
151 
152  _Thread_Dispatch_enable( _Per_CPU_Get() );
153 #endif
154  } else {
155  if ( the_semaphore->count < the_semaphore->Attributes.maximum_count )
156  the_semaphore->count += 1;
157  else
159 
160  _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
161  }
162 
163  return status;
164 }
165 
182  CORE_semaphore_Control *the_semaphore,
183  Thread_queue_Flush_callout remote_extract_callout,
184  uint32_t status
185 )
186 {
188  &the_semaphore->Wait_queue,
189  remote_extract_callout,
190  status
191  );
192 }
193 
203  const CORE_semaphore_Attributes *the_attribute
204 )
205 {
206  return ( the_attribute->discipline == CORE_SEMAPHORE_DISCIPLINES_PRIORITY );
207 }
208 
217  CORE_semaphore_Control *the_semaphore
218 )
219 {
220  return the_semaphore->count;
221 }
222 
240  CORE_semaphore_Control *the_semaphore,
241  Thread_Control *executing,
242  Objects_Id id,
243  bool wait,
244  Watchdog_Interval timeout,
245  ISR_lock_Context *lock_context
246 )
247 {
248  /* disabled when you get here */
249 
251  _Thread_queue_Acquire_critical( &the_semaphore->Wait_queue, lock_context );
252  if ( the_semaphore->count != 0 ) {
253  the_semaphore->count -= 1;
254  _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
255  return;
256  }
257 
258  if ( !wait ) {
259  _Thread_queue_Release( &the_semaphore->Wait_queue, lock_context );
261  return;
262  }
263 
264  executing->Wait.id = id;
266  &the_semaphore->Wait_queue,
267  executing,
269  timeout,
271  lock_context
272  );
273 }
274 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif
282 /* end of include file */
This status indicates that an attempt was made to unlock the semaphore and this would have made its c...
Definition: coresemimpl.h:60
CORE_semaphore_Disciplines discipline
This field indicates whether threads waiting on the semaphore block in FIFO or priority order...
Definition: coresem.h:62
void(* CORE_semaphore_API_mp_support_callout)(Thread_Control *, Objects_Id)
The following type defines the callout which the API provides to support global/multiprocessor operat...
Definition: coresemimpl.h:74
This status indicates that the calling task did not want to block and the operation was unable to com...
Definition: coresemimpl.h:47
RTEMS_INLINE_ROUTINE void _CORE_semaphore_Flush(CORE_semaphore_Control *the_semaphore, Thread_queue_Flush_callout remote_extract_callout, uint32_t status)
Core semaphore flush.
Definition: coresemimpl.h:181
RTEMS_INLINE_ROUTINE void _CORE_semaphore_Seize(CORE_semaphore_Control *the_semaphore, Thread_Control *executing, Objects_Id id, bool wait, Watchdog_Interval timeout, ISR_lock_Context *lock_context)
This routine attempts to receive a unit from the_semaphore.
Definition: coresemimpl.h:239
#define RTEMS_INLINE_ROUTINE
The following (in conjunction with compiler arguments) are used to choose between the use of static i...
Definition: basedefs.h:135
RTEMS_INLINE_ROUTINE void _Thread_Dispatch_enable(Per_CPU_Control *cpu_self)
Enables thread dispatching.
Definition: threaddispatch.h:304
The following defines the control block used to manage each counting semaphore.
Definition: coresem.h:69
uint32_t return_code
This field will contain the return status from a blocking operation.
Definition: thread.h:317
This status indicates that the thread was blocked waiting for an operation to complete and the semaph...
Definition: coresemimpl.h:51
void _Thread_queue_Flush(Thread_queue_Control *the_thread_queue, Thread_queue_Flush_callout remote_extract_callout, uint32_t status)
Unblocks all threads blocked on the_thread_queue.
Definition: threadqflush.c:24
RTEMS_INLINE_ROUTINE Per_CPU_Control * _Thread_Dispatch_disable(void)
Disables thread dispatching.
Definition: threaddispatch.h:277
CORE_semaphore_Status
Core Semaphore handler return statuses.
Definition: coresemimpl.h:40
void _Thread_queue_Enqueue_critical(Thread_queue_Control *the_thread_queue, Thread_Control *the_thread, States_Control state, Watchdog_Interval timeout, uint32_t timeout_code, ISR_lock_Context *lock_context)
Blocks the thread and places it on the thread queue.
Definition: threadqenqueue.c:48
void _Thread_queue_Extract_critical(Thread_queue_Control *the_thread_queue, Thread_Control *the_thread, ISR_lock_Context *lock_context)
Extracts the thread from the thread queue and unblocks it.
Definition: threadqenqueue.c:152
Objects_Control Object
This field is the object management structure for each thread.
Definition: thread.h:673
This structure defines the Thread Control Block (TCB).
Definition: thread.h:671
RTEMS_INLINE_ROUTINE bool _CORE_semaphore_Is_priority(const CORE_semaphore_Attributes *the_attribute)
This function returns true if the priority attribute is enabled in the attribute_set and false otherw...
Definition: coresemimpl.h:202
Objects_Id id
This field is the Id of the object this thread is waiting upon.
Definition: thread.h:302
Constants and Structures Associated with the Manipulation of Objects.
This status indicates that the operation completed successfully.
Definition: coresemimpl.h:42
This status indicates that the calling task was willing to block but the operation was unable to comp...
Definition: coresemimpl.h:56
The following defines the control block used to manage the attributes of each semaphore.
Definition: coresem.h:56
Inlined Routines Associated with Thread State Information.
This specifies that threads will wait for the semaphore in priority order.
Definition: coresem.h:49
uint32_t Watchdog_Interval
Type is used to specify the length of intervals.
Definition: watchdog.h:47
RTEMS_INLINE_ROUTINE CORE_semaphore_Status _CORE_semaphore_Surrender(CORE_semaphore_Control *the_semaphore, Objects_Id id, CORE_semaphore_API_mp_support_callout api_semaphore_mp_support, ISR_lock_Context *lock_context)
Surrender a unit to a semaphore.
Definition: coresemimpl.h:122
void _CORE_semaphore_Initialize(CORE_semaphore_Control *the_semaphore, const CORE_semaphore_Attributes *the_semaphore_attributes, uint32_t initial_value)
Initialize the semaphore based on the parameters passed.
Definition: coresem.c:23
RTEMS_INLINE_ROUTINE uint32_t _CORE_semaphore_Get_count(CORE_semaphore_Control *the_semaphore)
This routine returns the current count associated with the semaphore.
Definition: coresemimpl.h:216
#define STATES_WAITING_FOR_SEMAPHORE
This macro corresponds to a task waiting for a semaphore.
Definition: statesimpl.h:58
Local ISR lock context for acquire and release pairs.
Definition: isrlock.h:65
CORE_semaphore_Attributes Attributes
This element is the set of attributes which define this instance&#39;s behavior.
Definition: coresem.h:77
RTEMS_INLINE_ROUTINE Thread_Control * _Thread_queue_First_locked(Thread_queue_Control *the_thread_queue)
Returns the first thread on the thread queue if it exists, otherwise NULL.
Definition: threadqimpl.h:293
RTEMS_INLINE_ROUTINE bool _Objects_Is_local_id(Objects_Id id)
This function returns true if the id is of a local object, and false otherwise.
Definition: objectimpl.h:766
Inlined Routines in the Object Handler.
uint32_t Objects_Id
The following type defines the control block used to manage object IDs.
Definition: object.h:122
Thread_queue_Control Wait_queue
This field is the Waiting Queue used to manage the set of tasks which are blocked waiting to obtain t...
Definition: coresem.h:73
Thread_Wait_information Wait
This field is the blocking information for this thread.
Definition: thread.h:715
void(* Thread_queue_Flush_callout)(Thread_Control *)
The following type defines the callout used when a remote task is extracted from a local thread queue...
Definition: threadqimpl.h:65
Data Associated with the Counting Semaphore Handler.
uint32_t count
This element contains the current count of this semaphore.
Definition: coresem.h:79
uint32_t maximum_count
This element indicates the maximum count this semaphore may have.
Definition: coresem.h:58
Objects_Id id
This is the object&#39;s ID.
Definition: object.h:236