Loading...
Searching...
No Matches
condition.hpp
Go to the documentation of this file.
/*********************************************************************/
// libthreadar - is a library providing several C++ classes to work with threads
// Copyright (C) 2014-2025 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_CONDITION_HPP
#define LIBTHREADAR_CONDITION_HPP
#include "mutex.hpp"
#include "exceptions.hpp"
#include <deque>
namespace libthreadar
{
class condition : public mutex
{
public:
condition(unsigned int num = 1);
condition(const condition & ref) = delete;
condition(condition && ref) = default;
condition & operator = (const condition & ref) = delete;
condition & operator = (condition && ref) noexcept = default;
~condition();
void wait(unsigned int instance = 0);
void signal(unsigned int instance = 0);
void broadcast(unsigned int instance = 0);
unsigned int get_waiting_thread_count(unsigned int instance = 0) const { return counter[instance]; };
private:
std::deque<pthread_cond_t> cond;
std::deque<unsigned int> counter;
};
} // end of namespace
#endif
libthreadar::condition
Wrapper around the Posix pthread_cond_t object and its associated mutex.
Definition condition.hpp:50
libthreadar::condition::condition
condition(unsigned int num=1)
constructor
libthreadar::condition::operator=
condition & operator=(const condition &ref)=delete
no assignment operator
libthreadar::condition::get_waiting_thread_count
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
libthreadar::condition::condition
condition(condition &&ref)=default
no move constructor
libthreadar::condition::condition
condition(const condition &ref)=delete
no copy constructor
libthreadar::condition::wait
void wait(unsigned int instance=0)
put the calling thread on hold waiting for another thread to call signal()
libthreadar::condition::signal
void signal(unsigned int instance=0)
awakes a single thread suspended for having called wait() on the condition given in argument
libthreadar::condition::broadcast
void broadcast(unsigned int instance=0)
awakes all threads suspended for having called wait() on the condition given in argument
libthreadar::condition::~condition
~condition()
destructor
libthreadar::mutex
Wrapper around the Posix pthread_mutex_t C objects.
Definition mutex.hpp:57
exceptions.hpp
defines a set of exceptions that are used by libthreadar to report error situations
mutex.hpp
defines the mutex C++ class
libthreadar
This is the only namespace used in libthreadar and all symbols provided by libthreadar are member of ...
Definition barrier.hpp:46