libUTL++
Semaphore.h
1 #pragma once
2 
4 
5 #include <libutl/host_thread.h>
6 #include <libutl/NamedObjectMI.h>
7 
9 
10 UTL_NS_BEGIN;
11 
13 
21 
23 class Semaphore : public Object, public NamedObjectMI
24 {
27 
28 public:
34  {
35  init(count);
36  }
37 
42  bool trydown();
43 
45  void down();
46 
48  void up();
49 
51  void
52  tryP()
53  {
54  trydown();
55  }
56 
58  void
59  P()
60  {
61  down();
62  }
63 
65  void
66  V()
67  {
68  up();
69  }
70 
71 private:
72  void init(uint_t count = 1);
73  void deInit();
74 
75 private:
76 #if UTL_HOST_OS == UTL_OS_MINGW
77  HANDLE _sem;
78 #else
79  sem_t _sem;
80 #endif
81 };
82 
84 
85 UTL_NS_END;
void V()
Alias for up().
Definition: Semaphore.h:66
Named object mix-in.
Definition: NamedObjectMI.h:24
void deInit()
De-initialize UTL++.
Counter for resources shared between threads.
Definition: Semaphore.h:23
#define UTL_CLASS_DECL(DC, BC)
Declaration of standard UTL++ functionality for a non-template class.
Definition: macros.h:688
void P()
Alias for down().
Definition: Semaphore.h:59
Semaphore(uint_t count)
Constructor.
Definition: Semaphore.h:33
unsigned int uint_t
Unsigned integer.
Definition: types.h:59
#define UTL_CLASS_NO_COPY
Declare that a class cannot do copy().
Definition: macros.h:358
Root of UTL++ class hierarchy.
Definition: Object.h:52
void tryP()
Alias for trydown().
Definition: Semaphore.h:52
void init()
Initialize UTL++.
size_t count(const FwdIt &begin, const FwdIt &end, const Predicate *pred=nullptr, bool predVal=true)
Count objects that satisfy a Predicate.