-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunBoard.hpp
48 lines (40 loc) · 824 Bytes
/
unBoard.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
#ifndef _UNBOARD_HPP_
#define _UNBOARD_HPP_
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/sync/named_mutex.hpp>
using namespace boost::interprocess;
template < class T >
class unBoard
{
T *data;
managed_shared_memory managed_shm;
named_mutex mtx;
public:
unBoard()
:managed_shm(open_or_create, "unBoard", 1024),
mtx(open_or_create, typeid(T).name())
{
data = managed_shm.find_or_construct<T>(typeid(T).name())();
mtx.unlock();
}
~unBoard()
{
mtx.remove(typeid(T).name());
managed_shm.destroy<T>(typeid(T).name());
}
void save(T teste)
{
mtx.lock();
*data = teste;
mtx.unlock();
}
T load()
{
return *data;
}
};
/*
* g++ -c -Wall teste.cpp -lpthread
* g++ -L /lib -lpthread teste.o -o teste -lrt -lpthread
*/
#endif