-
Notifications
You must be signed in to change notification settings - Fork 1
/
SharedStruct.hpp
59 lines (50 loc) · 1.34 KB
/
SharedStruct.hpp
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
#pragma once
#include<boost/interprocess/managed_shared_memory.hpp>
#include<boost/interprocess/allocators/allocator.hpp>
#include<boost/interprocess/sync/scoped_lock.hpp>
#include<boost/interprocess/sync/interprocess_condition.hpp>
#include<boost/interprocess/containers/vector.hpp>
#include<cstdint>
using namespace boost::interprocess;
typedef allocator<uint8_t, managed_shared_memory::segment_manager> ShmemAllocator;
typedef vector<uint8_t, ShmemAllocator> SharedVector;
enum class ProcStatus {
init,
ready,
print_signals,
get_signal_handle,
read,
write,
sleep,
close,
error
};
class SharedStruct {
public:
SharedStruct() :
sleep_cycles(0),
proc_status(ProcStatus::init),
handle(0),
closed(false) {}
virtual ~SharedStruct(){}
uint64_t sleep_cycles;
ProcStatus proc_status;
size_t handle;
bool closed;
class {
public:
void wait(){
scoped_lock<interprocess_mutex> b_lock(b_mutex);
if(blocked){
blocked = false;
b_block.notify_one();
}else{
blocked = true;
b_block.wait(b_lock);
}
}
bool blocked = false;
interprocess_mutex b_mutex;
interprocess_condition b_block;
} barrier;
};