RTEMS  5.0.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
semaphoreimpl.h
1 /*
2  * Copyright (c) 2015, 2017 embedded brains GmbH. All rights reserved.
3  *
4  * embedded brains GmbH
5  * Dornierstr. 4
6  * 82178 Puchheim
7  * Germany
8  * <rtems@embedded-brains.de>
9  *
10  * The license and distribution terms for this file may be
11  * found in the file LICENSE in this distribution or at
12  * http://www.rtems.org/license/LICENSE.
13  */
14 
15 #ifndef _RTEMS_SCORE_SEMAPHOREIMPL_H
16 #define _RTEMS_SCORE_SEMAPHOREIMPL_H
17 
18 #include <sys/lock.h>
19 
20 #include <rtems/score/percpu.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26 
27 typedef struct {
29  unsigned int count;
30 } Sem_Control;
31 
32 #define SEMAPHORE_TQ_OPERATIONS &_Thread_queue_Operations_priority
33 
34 static inline Sem_Control *_Sem_Get( struct _Semaphore_Control *_sem )
35 {
36  return (Sem_Control *) _sem;
37 }
38 
39 static inline Thread_Control *_Sem_Queue_acquire_critical(
40  Sem_Control *sem,
41  Thread_queue_Context *queue_context
42 )
43 {
44  Thread_Control *executing;
45 
46  executing = _Thread_Executing;
47  _Thread_queue_Queue_acquire_critical(
48  &sem->Queue.Queue,
49  &executing->Potpourri_stats,
50  &queue_context->Lock_context.Lock_context
51  );
52 
53  return executing;
54 }
55 
56 static inline void _Sem_Queue_release(
57  Sem_Control *sem,
58  ISR_Level level,
59  Thread_queue_Context *queue_context
60 )
61 {
62  _Thread_queue_Queue_release_critical(
63  &sem->Queue.Queue,
64  &queue_context->Lock_context.Lock_context
65  );
66  _ISR_Local_enable( level );
67 }
68 
69 #ifdef __cplusplus
70 }
71 #endif /* __cplusplus */
72 
73 #endif /* _RTEMS_SCORE_SEMAPHOREIMPL_H */
Thread queue context for the thread queue methods.
Definition: threadq.h:193
uint32_t ISR_Level
Definition: isrlevel.h:38
Definition: thread.h:728
Thread queue with a layout compatible to struct _Thread_queue_Queue defined in Newlib <sys/lock...
Definition: threadqimpl.h:51
Thread_queue_Lock_context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:198
#define _ISR_Local_enable(_level)
Enables interrupts on this processor.
Definition: isrlevel.h:71
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:125
Definition: semaphoreimpl.h:27