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_CONDITIONBANK_H
14 #define JUNCTION_STRIPED_CONDITIONBANK_H
16 #include <junction/Core.h>
17 #include <junction/striped/ConditionPair.h>
19 #if JUNCTION_USE_STRIPING
21 //-----------------------------------
23 //-----------------------------------
24 #include <turf/impl/Mutex_SpinLock.h>
25 #include <turf/Util.h>
32 static const ureg SizeMask = 1023;
33 turf::Mutex_SpinLock m_initSpinLock;
34 turf::Atomic<ConditionPair*> m_pairs;
36 ConditionPair* initialize();
39 ConditionPair& get(void* ptr) {
40 ConditionPair* pairs = m_pairs.load(turf::Consume);
44 ureg index = turf::util::avalanche(uptr(ptr)) & SizeMask;
49 extern ConditionBank DefaultConditionBank;
51 } // namespace striped
52 } // namespace junction
54 #define JUNCTION_STRIPED_CONDITIONBANK_DEFINE_MEMBER()
55 #define JUNCTION_STRIPED_CONDITIONBANK_GET(objectPtr) (junction::striped::DefaultConditionBank.get(objectPtr))
57 #else // JUNCTION_USE_STRIPING
59 //-----------------------------------
61 //-----------------------------------
62 #define JUNCTION_STRIPED_CONDITIONBANK_DEFINE_MEMBER() junction::striped::ConditionPair m_conditionPair;
63 #define JUNCTION_STRIPED_CONDITIONBANK_GET(objectPtr) ((objectPtr)->m_conditionPair)
65 #endif // JUNCTION_USE_STRIPING
67 #endif // JUNCTION_STRIPED_CONDITIONBANK_H