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