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> |
---|
21 | #include <rtems/score/threadqimpl.h> |
---|
22 | |
---|
23 | #ifdef __cplusplus |
---|
24 | extern "C" { |
---|
25 | #endif /* __cplusplus */ |
---|
26 | |
---|
27 | typedef struct { |
---|
28 | Thread_queue_Syslock_queue Queue; |
---|
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 */ |
---|