BDS Public
Beam-lib  2.16.3
This is the Beam C++ class library.
BSemaphore.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * BSemaphore.h Semaphore Classes
3  * T.Barnaby, BEAM Ltd, 2012-11-17
4  * Copyright (c) 2012 All Right Reserved, Beam Ltd, http://www.beam.ltd.uk
5  *******************************************************************************
6  */
7 #ifndef BSemaphore_h
8 #define BSemaphore_h 1
9 
10 #include <BTypes.h>
11 #include <BMutex.h>
12 #include <semaphore.h>
13 
15 class BSemaphore {
16 public:
17  BSemaphore();
18  BSemaphore(const BSemaphore& semaphore);
19  ~BSemaphore();
20 
21  Bool wait(BTimeout timeoutUs = BTimeoutForever);
22  void set();
23 
24  int getValue() const;
25  BSemaphore& operator=(const BSemaphore& semaphore);
26 
27 private:
28  sem_t osema;
29 };
30 
32 public:
34  BSemaphoreBool(const BSemaphoreBool& semaphore);
36 
37  void set(Bool on = 1);
38  void clear();
39  Bool wait(Bool v = 1, BTimeout timeoutUs = BTimeoutForever);
40  Bool value();
41 
42  operator int();
43  int operator==(Bool on);
45 
46 private:
47  BSemaphore osema;
48  volatile Bool ovalue;
49 };
50 
52 public:
54  BSemaphoreCount(const BSemaphoreCount& semaphore);
56 
57  void setValue(BUInt v);
58  void add(int v = 1);
59  Bool wait(BUInt v = 1, BTimeout timeoutUs = BTimeoutForever);
60  Bool take(BUInt v = 1, BTimeout timeoutUs = BTimeoutForever);
61 
62  BUInt value();
63 
64  BSemaphoreCount& operator=(const BSemaphoreCount& semaphore);
65 
66 private:
67  BMutex olock;
68  BSemaphore osema;
69  volatile BUInt ovalue;
70 };
71 #endif
BSemaphoreBool()
Definition: BSemaphore.cpp:61
Semaphore class.
Definition: BSemaphore.h:15
BSemaphoreCount()
Definition: BSemaphore.cpp:111
BSemaphoreBool & operator=(Bool on)
Definition: BSemaphore.cpp:103
void set(Bool on=1)
Definition: BSemaphore.cpp:72
bool Bool
Definition: BTypes.h:15
~BSemaphore()
Definition: BSemaphore.cpp:24
void add(int v=1)
Set the semaphore.
Definition: BSemaphore.cpp:127
BSemaphoreCount & operator=(const BSemaphoreCount &semaphore)
Definition: BSemaphore.cpp:119
BUInt32 BTimeout
Definition: BTypes.h:42
void setValue(BUInt v)
Definition: BSemaphore.cpp:153
BSemaphore()
Definition: BSemaphore.cpp:10
BUInt value()
Definition: BSemaphore.cpp:160
Bool wait(BTimeout timeoutUs=BTimeoutForever)
Wait for the semaphore.
Definition: BSemaphore.cpp:32
Definition: BSemaphore.h:31
int operator==(Bool on)
Definition: BSemaphore.cpp:98
Bool value()
Definition: BSemaphore.cpp:90
BUInt32 BUInt
Definition: BTypes.h:30
const BTimeout BTimeoutForever
Definition: BTypes.h:43
Bool take(BUInt v=1, BTimeout timeoutUs=BTimeoutForever)
Take for the semaphore.
Definition: BSemaphore.cpp:142
void clear()
Definition: BSemaphore.cpp:77
Definition: BMutex.h:14
BSemaphore & operator=(const BSemaphore &semaphore)
Definition: BSemaphore.cpp:18
void set()
Set the semaphore.
Definition: BSemaphore.cpp:28
~BSemaphoreCount()
Definition: BSemaphore.cpp:124
Bool wait(BUInt v=1, BTimeout timeoutUs=BTimeoutForever)
Wait for the semaphore.
Definition: BSemaphore.cpp:134
Definition: BSemaphore.h:51
int getValue() const
Definition: BSemaphore.cpp:52
Bool wait(Bool v=1, BTimeout timeoutUs=BTimeoutForever)
Wait for the semaphore.
Definition: BSemaphore.cpp:82
~BSemaphoreBool()
Definition: BSemaphore.cpp:69