Loading...
Searching...
No Matches
freezer.hpp
Go to the documentation of this file.
/*********************************************************************/
// libthreadar - is a library providing several C++ classes to work with threads
// Copyright (C) 2014-2024 Denis Corbin
//
// This file is part of libthreadar
//
// libthreadar is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// libhtreadar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with libthreadar. If not, see <http://www.gnu.org/licenses/>
//
//----
// to contact the author: dar.linux@free.fr
/*********************************************************************/
#ifndef LIBTHREADAR_FREEZER_HPP
#define LIBTHREADAR_FREEZER_HPP
#include "config.h"
// C system headers
extern "C"
{
}
// C++ standard headers
#include <string>
// libthreadar headers
#include "condition.hpp"
namespace libthreadar
{
class freezer
{
public:
freezer();
freezer(const freezer & ref) = delete;
freezer(freezer && ref) = default;
freezer & operator = (const freezer & ref) = delete;
freezer & operator = (freezer && ref) noexcept = default;
~freezer();
bool waiting_thread() const;
void lock();
void unlock();
void reset();
int get_value() const { return value; };
private:
int value; //< this is the freezer value
condition cond; //< to protect access to value
};
} // end of namespace
#endif
libthreadar::condition
Wrapper around the Posix pthread_cond_t object and its associated mutex.
Definition condition.hpp:46
libthreadar::freezer
Class freezer is a semaphore like construct that has no maximum value.
Definition freezer.hpp:55
libthreadar::freezer::lock
void lock()
Request a "resource".
libthreadar::freezer::waiting_thread
bool waiting_thread() const
Return whether the freezer has at least a pending thread waiting for another thread to unlock it.
libthreadar::freezer::freezer
freezer()
freezer constuctor
libthreadar::freezer::~freezer
~freezer()
Destructor.
libthreadar::freezer::get_value
int get_value() const
Return the value of the freezer, that's to say the number of available "resources".
Definition freezer.hpp:98
libthreadar::freezer::freezer
freezer(const freezer &ref)=delete
no copy constructor
libthreadar::freezer::unlock
void unlock()
Release a "resource".
libthreadar::freezer::reset
void reset()
Reset to initial state releasing any thread that could wait on the freezer.
libthreadar::freezer::freezer
freezer(freezer &&ref)=default
no move constructor
libthreadar::freezer::operator=
freezer & operator=(const freezer &ref)=delete
no assignment operator (made private)
condition.hpp
defines the condition class
libthreadar
This is the only namespace used in libthreadar and all symbols provided by libthreadar are member of ...
Definition barrier.hpp:46