Libthreadar 1.6.0
freezer.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_FREEZER_HPP
25#define LIBTHREADAR_FREEZER_HPP
26
30
31#include "config.h"
32
33 // C system headers
34extern "C"
35{
36
37}
38 // C++ standard headers
39#include <string>
40
41
42 // libthreadar headers
43#include "condition.hpp"
44
45namespace libthreadar
46{
47
49
54 class freezer
55 {
56 public:
59
61 freezer(const freezer & ref) = delete;
62
64 freezer(freezer && ref) = default;
65
67 freezer & operator = (const freezer & ref) = delete;
68
70 freezer & operator = (freezer && ref) noexcept = default;
71
74
76 bool waiting_thread() const;
77
78
80
84 void lock();
85
87
90 void unlock();
91
93 void reset();
94
96
99 int get_value() const { return value; };
100
101 private:
102 int value; //< this is the freezer value
103 condition cond; //< to protect access to value
104 };
105
106} // end of namespace
107
108#endif
Wrapper around the Posix pthread_cond_t object and its associated mutex.
Definition: condition.hpp:50
Class freezer is a semaphore like construct that has no maximum value.
Definition: freezer.hpp:55
void lock()
Request a "resource".
bool waiting_thread() const
Return whether the freezer has at least a pending thread waiting for another thread to unlock it.
freezer()
freezer constuctor
~freezer()
Destructor.
int get_value() const
Return the value of the freezer, that's to say the number of available "resources".
Definition: freezer.hpp:99
freezer(const freezer &ref)=delete
no copy constructor
void unlock()
Release a "resource".
void reset()
Reset to initial state releasing any thread that could wait on the freezer.
freezer(freezer &&ref)=default
no move constructor
freezer & operator=(const freezer &ref)=delete
no assignment operator (made private)
defines the condition class
This is the only namespace used in libthreadar and all symbols provided by libthreadar are member of ...
Definition: barrier.hpp:46