Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Condition.h
Go to the documentation of this file.
1#pragma once
2#include <atomic>
3#include <misc/gen/Mutex.h>
4#include <misc/gen/TimeSpec.h>
5#include <misc/global.h>
6
7namespace sf
8{
9
16{
17 public:
21 typedef ::pthread_cond_t* handle_type;
22
26 explicit Condition(const std::string& name = "");
27
32
40 bool wait(Mutex& mutex, const TimeSpec& timeout = TimeSpec());
41
46 bool notifyOne();
47
52 int notifyAll();
53
57 operator handle_type();
58
62 const Condition& operator=(const Condition&) = delete;
63
67 int getWaiting() const;
68
69 const std::string& getName();
70
71 private:
75 std::atomic<int> _waiting{0};
79 ::pthread_cond_t _cond{};
83 std::string _name;
84};
85
86inline Condition::operator handle_type()
87{
88 return &_cond;
89}
90
91}// namespace sf
Wrapper for the pthread_cond mechanism.
Definition Condition.h:16
bool notifyOne()
Signals a single thread.
int notifyAll()
Signals all threads.
~Condition()
Destructor.
bool wait(Mutex &mutex, const TimeSpec &timeout=TimeSpec())
Waits for a signal with a timeout when a non-zero timeout is passed.
::pthread_cond_t * handle_type
Handle type.
Definition Condition.h:21
const Condition & operator=(const Condition &)=delete
Prevent copying.
Condition(const std::string &name="")
Constructor.
int getWaiting() const
Returns the amount of threads waiting.
const std::string & getName()
Lightweight intra process thread synchronization.
Definition Mutex.h:17
#define _MISC_CLASS
Definition misc/global.h:40
Definition Application.h:10
Class wrapper for timespec structure to modify.
Definition TimeSpec.h:12