Mantid
Loading...
Searching...
No Matches
Framework
PythonInterface
core
src
GlobalInterpreterLock.cpp
Go to the documentation of this file.
1
// Mantid Repository : https://github.com/mantidproject/mantid
2
//
3
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
// NScD Oak Ridge National Laboratory, European Spallation Source,
5
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#include "
MantidPythonInterface/core/GlobalInterpreterLock.h
"
8
#include "
MantidPythonInterface/core/VersionCompat.h
"
9
10
namespace
Mantid::PythonInterface
{
11
12
//------------------------------------------------------------------------------
13
// GlobalInterpreterLock Static helpers
14
//------------------------------------------------------------------------------
15
20
bool
GlobalInterpreterLock::locked
() {
21
#if defined(IS_PY3K)
22
return
(PyGILState_Check() == 1);
23
#else
24
PyThreadState *ts = _PyThreadState_Current;
25
return
(ts && ts == PyGILState_GetThisThreadState());
26
#endif
27
}
28
32
PyGILState_STATE
GlobalInterpreterLock::acquire
() {
return
PyGILState_Ensure(); }
33
40
void
GlobalInterpreterLock::release
(PyGILState_STATE tstate) { PyGILState_Release(tstate); }
41
42
//------------------------------------------------------------------------------
43
// GlobalInterpreterLock Public members
44
//------------------------------------------------------------------------------
45
49
GlobalInterpreterLock::GlobalInterpreterLock
() : m_state(this->acquire()) {}
50
55
GlobalInterpreterLock::~GlobalInterpreterLock
() { this->
release
(
m_state
); }
56
57
}
// namespace Mantid::PythonInterface
GlobalInterpreterLock.h
VersionCompat.h
Mantid::PythonInterface::GlobalInterpreterLock::~GlobalInterpreterLock
~GlobalInterpreterLock()
Destructor.
Definition:
GlobalInterpreterLock.cpp:55
Mantid::PythonInterface::GlobalInterpreterLock::locked
static bool locked()
Check if the current thread has the lock.
Definition:
GlobalInterpreterLock.cpp:20
Mantid::PythonInterface::GlobalInterpreterLock::release
static void release(PyGILState_STATE tstate)
Call PyGILState_Release.
Definition:
GlobalInterpreterLock.cpp:40
Mantid::PythonInterface::GlobalInterpreterLock::acquire
static PyGILState_STATE acquire()
Call PyGILState_Ensure.
Definition:
GlobalInterpreterLock.cpp:32
Mantid::PythonInterface::GlobalInterpreterLock::m_state
PyGILState_STATE m_state
Current GIL state.
Definition:
GlobalInterpreterLock.h:43
Mantid::PythonInterface::GlobalInterpreterLock::GlobalInterpreterLock
GlobalInterpreterLock()
Default constructor.
Definition:
GlobalInterpreterLock.cpp:49
Mantid::PythonInterface
Definition:
CallMethod.h:17
Generated on Tue Jan 3 2023 11:57:58 for Mantid by
1.9.5