source: rtems/cpukit/score/include/rtems/score/semaphoreimpl.h @ c090db7

5
Last change on this file since c090db7 was c090db7, checked in by Sebastian Huber <sebastian.huber@…>, on 09/12/17 at 06:09:16

posix: Implement self-contained POSIX semaphores

For semaphore object pointer and object validation see
POSIX_SEMAPHORE_VALIDATE_OBJECT().

Destruction or close of a busy semaphore returns an error status. The
object is not flushed.

POSIX semaphores are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3116.

  • Property mode set to 100644
File size: 1.5 KB
Line 
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
24extern "C" {
25#endif /* __cplusplus */
26
27typedef 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
34static inline Sem_Control *_Sem_Get( struct _Semaphore_Control *_sem )
35{
36  return (Sem_Control *) _sem;
37}
38
39static 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
56static 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 */
Note: See TracBrowser for help on using the repository browser.