-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresource_manager.h
45 lines (36 loc) · 917 Bytes
/
resource_manager.h
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
#ifndef PLC_EMULATOR__RESOURCE_MANAGER_H_
#define PLC_EMULATOR__RESOURCE_MANAGER_H_
#include <syscall.h>
extern "C" {
#include "resource.h"
};
namespace plc_emulator {
class ResourceManager {
private:
ResourceImpl *associated_resource_;
std::mutex _lock;
pid_t resource_thread_pid_;
public:
ResourceManager(ResourceImpl *associated_resource) :
associated_resource_(associated_resource) {
resource_thread_pid_ = 0;
};
void set_tid() {
std::lock_guard<std::mutex> l(_lock);
resource_thread_pid_ = syscall(SYS_gettid);
}
pid_t get_tid() {
while (true) {
std::lock_guard<std::mutex> l(_lock);
if (resource_thread_pid_ != 0)
break;
}
return resource_thread_pid_;
}
void ExecuteResource();
void ExecuteResourceManager();
std::thread LaunchResource();
std::thread LaunchResourceManager();
};
}
#endif //PLC_EMULATOR__RESOURCE_MANAGER_H_