RTEMS
semaphoreimpl.h
Go to the documentation of this file.
1 
9 /*
10  * Copyright (c) 2015, 2017 embedded brains GmbH. All rights reserved.
11  *
12  * embedded brains GmbH
13  * Dornierstr. 4
14  * 82178 Puchheim
15  * Germany
16  * <rtems@embedded-brains.de>
17  *
18  * The license and distribution terms for this file may be
19  * found in the file LICENSE in this distribution or at
20  * http://www.rtems.org/license/LICENSE.
21  */
22 
23 #ifndef _RTEMS_SCORE_SEMAPHOREIMPL_H
24 #define _RTEMS_SCORE_SEMAPHOREIMPL_H
25 
26 #include <sys/lock.h>
27 
28 #include <rtems/score/percpu.h>
30 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif /* __cplusplus */
40 
41 typedef struct {
43  unsigned int count;
44 } Sem_Control;
45 
46 #define SEMAPHORE_TQ_OPERATIONS &_Thread_queue_Operations_priority
47 
55 static inline Sem_Control *_Sem_Get( struct _Semaphore_Control *_sem )
56 {
57  return (Sem_Control *) _sem;
58 }
59 
71  Sem_Control *sem,
72  Thread_queue_Context *queue_context
73 )
74 {
75  Thread_Control *executing;
76 
77  executing = _Thread_Executing;
78  _Thread_queue_Queue_acquire_critical(
79  &sem->Queue.Queue,
80  &executing->Potpourri_stats,
81  &queue_context->Lock_context.Lock_context
82  );
83 
84  return executing;
85 }
86 
94 static inline void _Sem_Queue_release(
95  Sem_Control *sem,
96  ISR_Level level,
97  Thread_queue_Context *queue_context
98 )
99 {
101  &sem->Queue.Queue,
102  &queue_context->Lock_context.Lock_context
103  );
104  _ISR_Local_enable( level );
105 }
106 
107 #ifdef __cplusplus
108 }
109 #endif /* __cplusplus */
110 
113 #endif /* _RTEMS_SCORE_SEMAPHOREIMPL_H */
Thread queue context for the thread queue methods.
Definition: threadq.h:198
static __inline__ void _Thread_queue_Queue_release_critical(Thread_queue_Queue *queue, ISR_lock_Context *lock_context)
Releases the thread queue queue in a critical section.
Definition: threadqimpl.h:603
static void _Sem_Queue_release(Sem_Control *sem, ISR_Level level, Thread_queue_Context *queue_context)
Releases the semaphore queue.
Definition: semaphoreimpl.h:94
Thread queue with a layout compatible to struct _Thread_queue_Queue defined in Newlib <sys/lock...
Definition: threadqimpl.h:54
uint32_t ISR_Level
Definition: isrlevel.h:41
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:203
static Thread_Control * _Sem_Queue_acquire_critical(Sem_Control *sem, Thread_queue_Context *queue_context)
Acquires the semaphore queue critical.
Definition: semaphoreimpl.h:70
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:74
Constants and Structures Associated with the Manipulation of Objects.
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:130
static Sem_Control * _Sem_Get(struct _Semaphore_Control *_sem)
Gets the Sem_Control * of the semaphore.
Definition: semaphoreimpl.h:55