-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGILManager.cpp
65 lines (57 loc) · 1.47 KB
/
GILManager.cpp
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
#include "stdafx.h"
#include "GILManager.h"
namespace NppPythonScript
{
// GILManager* GILManager::s_gilManagerInstance = NULL;
GILLock::GILLock()
: m_hasLock(false == doIHaveTheGIL())
{
if (m_hasLock)
{
//DEBUG_TRACE(L"Acquiring GIL...\n");
m_state = PyGILState_Ensure();
//DEBUG_TRACE(L"GIL Acquired.\n");
}
}
GILLock::~GILLock()
{
if (m_hasLock)
{
//DEBUG_TRACE(L"Releasing GIL...\n");
PyGILState_Release(m_state);
//DEBUG_TRACE(L"GIL Released.\n");
}
}
GILRelease::GILRelease()
: m_lockReleased(doIHaveTheGIL())
{
if (m_lockReleased)
{
//DEBUG_TRACE(L"Temp GIL Release requested\n");
m_threadState = PyEval_SaveThread();
}
else
{
//DEBUG_TRACE(L"Temp GIL Release ignored- we don't have the GIL\n");
}
}
GILRelease::~GILRelease()
{
if (m_lockReleased)
{
//DEBUG_TRACE(L"Re-acquiring GIL after temporary release\n");
PyEval_RestoreThread(m_threadState);
//DEBUG_TRACE(L"GIL reacquired after temporary release\n");
}
}
void GILRelease::reacquire()
{
if (m_lockReleased)
{
//DEBUG_TRACE(L"GILRelease::reacquire() - reacquiring GIL\n");
PyEval_RestoreThread(m_threadState);
//DEBUG_TRACE(L"GIL Reacquired after temporary release (in reacquire())\n");
m_lockReleased = false;
}
}
}