Libthreadar 1.6.0
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-2025 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
43
48
49 class condition : public mutex
50 {
51 public:
52
54
57 condition(unsigned int num = 1);
58
60 condition(const condition & ref) = delete;
61
63 condition(condition && ref) = default;
64
66 condition & operator = (const condition & ref) = delete;
67
69 condition & operator = (condition && ref) noexcept = default;
70
73
74
76
83 void wait(unsigned int instance = 0);
84
86
92 void signal(unsigned int instance = 0);
93
95
100 void broadcast(unsigned int instance = 0);
101
103
105 unsigned int get_waiting_thread_count(unsigned int instance = 0) const { return counter[instance]; };
106
107 private:
108 std::deque<pthread_cond_t> cond;
109 std::deque<unsigned int> counter;
110
111 };
112
114
115} // end of namespace
116
117#endif
Wrapper around the Posix pthread_cond_t object and its associated mutex.
Definition: condition.hpp:50
condition(unsigned int num=1)
constructor
condition & operator=(const condition &ref)=delete
no assignment operator
unsigned int get_waiting_thread_count(unsigned int instance=0) const
return the number of thread currently waiting on that condition
Definition: condition.hpp:105
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 for having called wait() on the condition given in argument
void broadcast(unsigned int instance=0)
awakes all threads suspended for having called wait() on the condition given in argument
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