Add data structure benchmarks
[c11concurrency-benchmarks.git] / cdschecker_modified_benchmarks / include / cds_threads.h
1 // Header to handle CDSChecker bullshit.
2 // Handles most things, not just threads:
3 //  - Catches C11 threads and forwards to C++11 threads.
4 //  - Catches store_n and load_n and turns them into normal stores/loads.
5 //  - Replaces user_main with just main.
6
7 #ifndef __THREADS_H__
8 #define __THREADS_H__
9
10 #ifdef __cplusplus
11 #include <thread>
12
13 #include <map>
14 #include <string>
15 #include <cassert>
16
17 #define thrd_t std::thread
18 typedef int (*thrd_start_t)(void *); 
19
20 static std::map<std::string, std::thread> thrs;
21
22 #define thrd_create(T, F, A) new_thread(#T, F, A)
23 static void new_thread(const char *t, thrd_start_t f, void *args) {
24   assert(thrs.emplace(std::string(++t), std::thread(*f, args)).second);
25 }
26
27 #define thrd_join(T) end_thread(#T)
28 static void end_thread(const char *t) {
29   thrs[std::string(t)].join();
30 }
31
32 #define thrd_yield() std::this_thread::yield()
33
34 #define user_main main
35
36 #endif
37
38 #endif  // __THREADS_H__