-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShared_state.h
More file actions
65 lines (56 loc) · 1.33 KB
/
Shared_state.h
File metadata and controls
65 lines (56 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//
// Created by Dima on 05.10.2017.
//
#ifndef SETTINGUPGOOGLETEST_SHARED_STATE_H
#define SETTINGUPGOOGLETEST_SHARED_STATE_H
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <exception>
#include <stdexcept>
#include "ThreadPool.h"
template<typename R>
class Shared_state {
public:
std::condition_variable sh_cv;
std::mutex sh_mtx;
std::atomic<bool> sh_done;
R data;
std::exception_ptr sh_ex_ptr;
std::atomic<bool> promise_al;
ThreadPool *pool = nullptr;
Shared_state() {
sh_done = false;
//promise_al = true;
}
};
template<typename R>
class Shared_state<R &> {
public:
std::condition_variable sh_cv;
std::mutex sh_mtx;
std::atomic<bool> sh_done;
R *data;
std::exception_ptr sh_ex_ptr;
std::atomic<bool> promise_al;
ThreadPool *pool = nullptr;
Shared_state() {
sh_done = false;
promise_al = true;
}
};
template<>
class Shared_state<void> {
public:
std::condition_variable sh_cv;
std::mutex sh_mtx;
std::atomic<bool> sh_done;
std::exception_ptr sh_ex_ptr;
std::atomic<bool> promise_al;
ThreadPool *pool = nullptr;
Shared_state() {
sh_done = false;
promise_al = true;
}
};
#endif //SETTINGUPGOOGLETEST_SHARED_STATE_H