Mantid
Loading...
Searching...
No Matches
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 +
9
11
12//------------------------------------------------------------------------------
13// GlobalInterpreterLock Static helpers
14//------------------------------------------------------------------------------
15
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
32PyGILState_STATE GlobalInterpreterLock::acquire() { return PyGILState_Ensure(); }
33
40void GlobalInterpreterLock::release(PyGILState_STATE tstate) { PyGILState_Release(tstate); }
41
42//------------------------------------------------------------------------------
43// GlobalInterpreterLock Public members
44//------------------------------------------------------------------------------
45
49GlobalInterpreterLock::GlobalInterpreterLock() : m_state(this->acquire()) {}
50
56
57} // namespace Mantid::PythonInterface
static bool locked()
Check if the current thread has the lock.
static void release(PyGILState_STATE tstate)
Call PyGILState_Release.
static PyGILState_STATE acquire()
Call PyGILState_Ensure.
PyGILState_STATE m_state
Current GIL state.