OpenWalnut  1.5.0dev
WConditionOneShot.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WCONDITIONONESHOT_H
26 #define WCONDITIONONESHOT_H
27 
28 #include <atomic>
29 #include <shared_mutex>
30 
31 #include <boost/thread.hpp>
32 
33 #include "WCondition.h"
34 
35 
36 /**
37  * Implements a WCondition, but can be fired only ONCE. This is useful if you want to have a thread waiting for a condition but
38  * you can not assure that the thread already waits when you set the condition. This would cause the thread to wait endlessly
39  * because it does not know that you already fired it.
40  */
42 {
43  friend class WConditionOneShot_test; //!< Access for test class.
44 public:
45  /**
46  * Default constructor.
47  */
49 
50  /**
51  * Destructor.
52  */
53  virtual ~WConditionOneShot();
54 
55  /**
56  * Wait for the condition. Sets the calling thread asleep.
57  */
58  virtual void wait() const;
59 
60  /**
61  * Notifies all waiting threads.
62  */
63  virtual void notify();
64 
65 protected:
66  /**
67  * Atomic bool whether this conditon has been done or not.
68  */
69  std::atomic< bool > m_isDone;
70 
71 private:
72 };
73 
74 #endif // WCONDITIONONESHOT_H
75 
Implements a WCondition, but can be fired only ONCE.
virtual void notify()
Notifies all waiting threads.
virtual void wait() const
Wait for the condition.
friend class WConditionOneShot_test
Access for test class.
WConditionOneShot()
Default constructor.
virtual ~WConditionOneShot()
Destructor.
std::atomic< bool > m_isDone
Atomic bool whether this conditon has been done or not.
Class to encapsulate boost::condition_variable_any.
Definition: WCondition.h:42