Initial commit
[junction.git] / junction / striped / ConditionBank.cpp
1 /*------------------------------------------------------------------------
2   Junction: Concurrent data structures in C++
3   Copyright (c) 2016 Jeff Preshing
4
5   Distributed under the Simplified BSD License.
6   Original location: https://github.com/preshing/junction
7
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 ------------------------------------------------------------------------*/
12
13 #include <junction/Core.h>
14 #include <junction/striped/ConditionBank.h>
15
16 #if JUNCTION_USE_STRIPING
17
18 namespace junction {
19 namespace striped {
20
21 ConditionBank DefaultConditionBank;
22
23 ConditionPair* ConditionBank::initialize() {
24     m_initSpinLock.lock();
25     ConditionPair* pairs = m_pairs.loadNonatomic();
26     if (!pairs) {
27         pairs = new ConditionPair[SizeMask + 1];
28         m_pairs.store(pairs, turf::Release);
29     }
30     m_initSpinLock.unlock();
31     return pairs;
32 }
33
34 } // namespace striped
35 } // namespace junction
36
37 #endif // JUNCTION_USE_STRIPING