Delete unused junction/Averager.h
[junction.git] / samples / MapCorrectnessTests / TestEnvironment.h
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 #ifndef SAMPLES_MAPCORRECTNESSTESTS_TESTENVIRONMENT_H
14 #define SAMPLES_MAPCORRECTNESSTESTS_TESTENVIRONMENT_H
15
16 #include <junction/Core.h>
17 #include <turf/extra/JobDispatcher.h>
18 #include <turf/Trace.h>
19 #include <junction/extra/MapAdapter.h>
20
21 using namespace turf::intTypes;
22 typedef junction::extra::MapAdapter MapAdapter;
23
24 struct TestEnvironment {
25     turf::extra::JobDispatcher dispatcher;
26     ureg numThreads;
27     MapAdapter adapter;
28     std::vector<MapAdapter::ThreadContext> threads;
29
30     TestEnvironment() : numThreads(dispatcher.getNumPhysicalCores()), adapter(numThreads) {
31         TURF_ASSERT(numThreads > 0);
32         for (ureg t = 0; t < numThreads; t++)
33             threads.emplace_back(adapter, t);
34         dispatcher.kickMulti(&MapAdapter::ThreadContext::registerThread, &threads[0], threads.size());
35     }
36
37     ~TestEnvironment() {
38         dispatcher.kickMulti(&MapAdapter::ThreadContext::unregisterThread, &threads[0], threads.size());
39     }
40 };
41
42
43 #endif // SAMPLES_MAPCORRECTNESSTESTS_TESTENVIRONMENT_H