RTEMS  5.0.0
barrierimpl.h
Go to the documentation of this file.
1 
10 /*
11  * COPYRIGHT (c) 1989-2011.
12  * On-Line Applications Research Corporation (OAR).
13  *
14  * Copyright (c) 2017 embedded brains GmbH
15  *
16  * The license and distribution terms for this file may be
17  * found in the file LICENSE in this distribution or at
18  * http://www.rtems.org/license/LICENSE.
19  */
20 
21 #ifndef _RTEMS_POSIX_BARRIERIMPL_H
22 #define _RTEMS_POSIX_BARRIERIMPL_H
23 
24 #include <errno.h>
25 #include <pthread.h>
26 
27 #include <rtems/score/percpu.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define POSIX_BARRIER_MAGIC 0x1cf03773UL
35 
36 #define POSIX_BARRIER_TQ_OPERATIONS &_Thread_queue_Operations_FIFO
37 
38 typedef struct {
39  unsigned long flags;
41  unsigned int count;
42  unsigned int waiting_threads;
44 
45 static inline POSIX_Barrier_Control *_POSIX_Barrier_Get(
46  pthread_barrier_t *_barrier
47 )
48 {
49  return (POSIX_Barrier_Control *) _barrier;
50 }
51 
52 static inline Thread_Control *_POSIX_Barrier_Queue_acquire(
53  POSIX_Barrier_Control *barrier,
54  Thread_queue_Context *queue_context
55 )
56 {
57  ISR_Level level;
58  Thread_Control *executing;
59 
60  _Thread_queue_Context_initialize( queue_context );
61  _Thread_queue_Context_ISR_disable( queue_context, level );
62  _Thread_queue_Context_set_ISR_level( queue_context, level );
63  executing = _Thread_Executing;
64  _Thread_queue_Queue_acquire_critical(
65  &barrier->Queue.Queue,
66  &executing->Potpourri_stats,
67  &queue_context->Lock_context.Lock_context
68  );
69 
70  return executing;
71 }
72 
73 static inline void _POSIX_Barrier_Queue_release(
74  POSIX_Barrier_Control *barrier,
75  Thread_queue_Context *queue_context
76 )
77 {
78  _Thread_queue_Queue_release(
79  &barrier->Queue.Queue,
80  &queue_context->Lock_context.Lock_context
81  );
82 }
83 
84 #define POSIX_BARRIER_VALIDATE_OBJECT( bar ) \
85  do { \
86  if ( \
87  ( bar ) == NULL \
88  || ( (uintptr_t) ( bar ) ^ POSIX_BARRIER_MAGIC ) != ( bar )->_flags \
89  ) { \
90  return EINVAL; \
91  } \
92  } while ( 0 )
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif
99 /* end of include file */
Thread queue context for the thread queue methods.
Definition: threadq.h:193
POSIX Threads Private Support.
RTEMS_INLINE_ROUTINE void _Thread_queue_Context_initialize(Thread_queue_Context *queue_context)
Initializes a thread queue context.
Definition: threadqimpl.h:108
Definition: barrierimpl.h:38
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
ISR_lock_Context Lock_context
The lock context for the thread queue acquire and release operations.
Definition: threadq.h:125