Fawkes API  Fawkes Development Version
interruptible_barrier.h
1 
2 /***************************************************************************
3  * interruptible_barrier.h - Interruptible Barrier
4  *
5  * Created: Sat Jan 31 12:27:54 2009
6  * Copyright 2006-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _CORE_THREADING_INTERRUPTIBLE_BARRIER_H_
25 #define _CORE_THREADING_INTERRUPTIBLE_BARRIER_H_
26 
27 #include <core/threading/barrier.h>
28 #include <core/utils/refptr.h>
29 
30 namespace fawkes {
31 
32 class InterruptibleBarrierData;
33 class ThreadList;
34 
36 {
37 public:
38  InterruptibleBarrier(unsigned int count);
39  InterruptibleBarrier(Mutex *mutex, unsigned int count);
40  virtual ~InterruptibleBarrier();
41 
42  bool wait(unsigned int timeout_sec, unsigned int timeout_nanosec);
43  virtual inline void
44  wait()
45  {
46  wait(0, 0);
47  }
48 
49  void interrupt() noexcept;
50  void reset() noexcept;
51 
53 
54  bool no_threads_in_wait();
55 
56 private:
59  InterruptibleBarrier &operator=(const InterruptibleBarrier &b);
60  InterruptibleBarrier &operator=(const InterruptibleBarrier *b);
61 
62 private:
63  InterruptibleBarrierData *data_;
64  RefPtr<ThreadList> passed_threads_;
65 
66  bool interrupted_;
67  bool timeout_;
68  bool wait_at_barrier_;
69  int num_threads_in_wait_function_;
70 };
71 
72 } // end namespace fawkes
73 
74 #endif
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
Definition: barrier.h:32
unsigned int count()
Get number of threads this barrier will wait for.
Definition: barrier.cpp:176
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
void interrupt() noexcept
Interrupt the barrier.
virtual void wait()
Wait for other threads.
InterruptibleBarrier(unsigned int count)
Constructor.
void reset() noexcept
Clears the barrier.
virtual ~InterruptibleBarrier()
Destructor.
bool no_threads_in_wait()
Checks if there are no more threads in the wait() function.
RefPtr< ThreadList > passed_threads()
Get a list of threads that passed the barrier.
Mutex mutual exclusion lock.
Definition: mutex.h:33
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:50
List of threads.
Definition: thread_list.h:56
Fawkes library namespace.