Loading...
Searching...
No Matches
barrier.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_BARRIER_HPP
#define LIBTHREADAR_BARRIER_HPP
#include "config.h"
// C system headers
extern "C"
{
#if HAVE_PTHREAD_H
#include <pthread.h>
#endif
}
// C++ standard headers
// libthreadar headers
#include "condition.hpp"
namespace libthreadar
{
class barrier
{
public:
barrier(unsigned int num);
barrier(const barrier & ref) = delete;
barrier(barrier && ref) noexcept = default;
barrier & operator = (const barrier & ref) = delete;
barrier & operator = (barrier && ref) noexcept = default;
~barrier() noexcept(false);
void wait();
unsigned int get_count() const { return val; };
unsigned int get_waiting_count() const { return waiting_num; };
static std::string used_implementation()
{
#if HAVE_PTHREAD_BARRIER_T
return "pthread_barrier_t";
#else
return "pthread_cond_t";
#endif
}
private:
unsigned int val;
unsigned int waiting_num;
#if HAVE_PTHREAD_BARRIER_T
pthread_barrier_t bar;
#else
condition cond;
#endif
};
} // end of namespace
#endif
libthreadar::barrier
the class barrier allows several threads to synchronize between them
Definition barrier.hpp:57
libthreadar::barrier::~barrier
~barrier() noexcept(false)
The destructor.
libthreadar::barrier::wait
void wait()
suspend the calling thread waiting for other up to 'num' other thread to call wait too
libthreadar::barrier::barrier
barrier(barrier &&ref) noexcept=default
no move constructor
libthreadar::barrier::barrier
barrier(unsigned int num)
The constructor.
libthreadar::barrier::get_count
unsigned int get_count() const
return the barrier size
Definition barrier.hpp:88
libthreadar::barrier::operator=
barrier & operator=(const barrier &ref)=delete
no assignment operator
libthreadar::barrier::get_waiting_count
unsigned int get_waiting_count() const
return the number of thread waiting on the barrier or just released from it
Definition barrier.hpp:95
libthreadar::barrier::barrier
barrier(const barrier &ref)=delete
no copy constructor
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