forked from Cryolite/kanachan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgil.hpp
51 lines (34 loc) · 1002 Bytes
/
gil.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
#if !defined(KANACHAN_SIMULATION_GIL_HPP_INCLUDE_GUARD)
#define KANACHAN_SIMULATION_GIL_HPP_INCLUDE_GUARD
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <mutex>
#include <thread>
#include <stop_token>
#include <chrono>
namespace Kanachan::GIL{
class RecursiveLock
{
public:
RecursiveLock();
RecursiveLock(RecursiveLock const &) = delete;
RecursiveLock(RecursiveLock &&rhs) noexcept;
~RecursiveLock();
RecursiveLock &operator=(RecursiveLock const &) = delete;
RecursiveLock &operator=(RecursiveLock &&rhs) noexcept;
private:
PyGILState_STATE state_;
bool owns_;
}; // class RecursiveLock
class RecursiveRelease
{
public:
RecursiveRelease();
RecursiveRelease(RecursiveRelease const &) = delete;
~RecursiveRelease();
RecursiveRelease &operator=(RecursiveRelease const &) = delete;
private:
PyThreadState *save_;
}; // class UniqueRelease
} // namespace Kanachan::GIL
#endif // !defined(KANACHAN_SIMULATION_GIL_HPP_INCLUDE_GUARD)