1 /*------------------------------------------------------------------------
2 Junction: Concurrent data structures in C++
3 Copyright (c) 2016 Jeff Preshing
5 Distributed under the Simplified BSD License.
6 Original location: https://github.com/preshing/junction
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the LICENSE file for more information.
11 ------------------------------------------------------------------------*/
13 #ifndef JUNCTION_STRIPED_AUTORESETEVENT_H
14 #define JUNCTION_STRIPED_AUTORESETEVENT_H
16 #include <junction/Core.h>
17 #include <junction/striped/ConditionBank.h>
22 class AutoResetEvent {
24 JUNCTION_STRIPED_CONDITIONBANK_DEFINE_MEMBER()
28 AutoResetEvent(bool status) : m_status(status) {
32 ConditionPair& pair = JUNCTION_STRIPED_CONDITIONBANK_GET(this);
33 turf::LockGuard<turf::Mutex> guard(pair.mutex);
35 pair.condVar.wait(guard);
40 ConditionPair& pair = JUNCTION_STRIPED_CONDITIONBANK_GET(this);
41 turf::LockGuard<turf::Mutex> guard(pair.mutex);
44 // FIXME: Is there a more efficient striped::Mutex implementation that is safe from deadlock?
45 // This approach will wake up too many threads when there is heavy contention.
46 // However, if we don't wakeAll(), we will miss wakeups, since ConditionPairs are shared.
47 pair.condVar.wakeAll();
52 } // namespace striped
53 } // namespace junction
55 #endif // JUNCTION_STRIPED_AUTORESETEVENT_H