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 #if 0 /* just to make Emacs auto-indent happy */
32 }
33 #endif
34 
35 class InterruptibleBarrierData;
36 class ThreadList;
37 
39 {
40  public:
41  InterruptibleBarrier(unsigned int count);
42  InterruptibleBarrier(Mutex *mutex, unsigned int count);
43  virtual ~InterruptibleBarrier();
44 
45  bool wait(unsigned int timeout_sec, unsigned int timeout_nanosec);
46  virtual inline void wait() { wait(0, 0); }
47 
48  void interrupt() throw();
49  void reset() throw();
50 
52 
53  bool no_threads_in_wait();
54 
55  private:
58  InterruptibleBarrier & operator=(const InterruptibleBarrier &b);
59  InterruptibleBarrier & operator=(const InterruptibleBarrier *b);
60 
61  private:
62  InterruptibleBarrierData *__data;
63  RefPtr<ThreadList> __passed_threads;
64 
65  bool __interrupted;
66  bool __timeout;
67  bool __wait_at_barrier;
68  int __num_threads_in_wait_function;
69 };
70 
71 
72 } // end namespace fawkes
73 
74 #endif
unsigned int count()
Get number of threads this barrier will wait for.
Definition: barrier.cpp:181
void interrupt()
Interrupt the barrier.
virtual void wait()
Wait for other threads.
bool no_threads_in_wait()
Checks if there are no more threads in the wait() function.
Fawkes library namespace.
virtual ~InterruptibleBarrier()
Destructor.
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
InterruptibleBarrier(unsigned int count)
Constructor.
RefPtr< ThreadList > passed_threads()
Get a list of threads that passed the barrier.
RefPtr<> is a reference-counting shared smartpointer.
Definition: refptr.h:49
void reset()
Clears the barrier.
Mutex mutual exclusion lock.
Definition: mutex.h:32
A barrier is a synchronization tool which blocks until a given number of threads have reached the bar...
Definition: barrier.h:32