Libthreadar 1.4.0
Loading...
Searching...
No Matches
condition.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// libthreadar - is a library providing several C++ classes to work with threads
3// Copyright (C) 2014-2020 Denis Corbin
4//
5// This file is part of libthreadar
6//
7// libthreadar is free software: you can redistribute it and/or modify
8// it under the terms of the GNU Lesser General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// libhtreadar is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU Lesser General Public License for more details.
16//
17// You should have received a copy of the GNU Lesser General Public License
18// along with libthreadar. If not, see <http://www.gnu.org/licenses/>
19//
20//----
21// to contact the author: dar.linux@free.fr
22/*********************************************************************/
23
24#ifndef LIBTHREADAR_CONDITION_HPP
25#define LIBTHREADAR_CONDITION_HPP
26
29
30#include "mutex.hpp"
31#include "exceptions.hpp"
32
33#include <deque>
34
35namespace libthreadar
36{
37
39
44
45 class condition : public mutex
46 {
47 public:
48
50
53 condition(unsigned int num = 1);
54
56 condition(const condition & ref) = delete;
57
59 condition(condition && ref) = default;
60
62 condition & operator = (const condition & ref) = delete;
63
65 condition & operator = (condition && ref) noexcept = default;
66
69
70
72
77 void wait(unsigned int instance = 0);
78
80
85 void signal(unsigned int instance = 0);
86
88
93 void broadcast(unsigned int instance = 0);
94
96
98 unsigned int get_waiting_thread_count(unsigned int instance = 0) { return counter[instance]; };
99
100 private:
101 std::deque<pthread_cond_t> cond;
102 std::deque<unsigned int> counter;
103
104 };
105
107
108} // end of namespace
109
110#endif
Wrapper around the Posix pthread_cond_t object and its associated mutex.
Definition condition.hpp:46
condition(unsigned int num=1)
constructor
unsigned int get_waiting_thread_count(unsigned int instance=0)
return the number of thread currently waiting on that condition
Definition condition.hpp:98
condition & operator=(const condition &ref)=delete
no assignment operator
condition(condition &&ref)=default
no move constructor
condition(const condition &ref)=delete
no copy constructor
void wait(unsigned int instance=0)
put the calling thread on hold waiting for another thread to call signal()
void signal(unsigned int instance=0)
awakes a single thread suspended after having called wait()
void broadcast(unsigned int instance=0)
awakes all threads suspended after having called wait()
Wrapper around the Posix pthread_mutex_t C objects.
Definition mutex.hpp:57
defines a set of exceptions that are used by libthreadar to report error situations
defines the mutex C++ class
This is the only namespace used in libthreadar and all symbols provided by libthreadar are member of ...
Definition barrier.hpp:46