Mantid
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Mantid::PythonInterface::GlobalInterpreterLock Class Reference

Defines a structure for acquiring/releasing the Python GIL using the RAII pattern. More...

#include <GlobalInterpreterLock.h>

Public Member Functions

 GlobalInterpreterLock ()
 Default constructor. More...
 
 ~GlobalInterpreterLock ()
 Destructor. More...
 

Static Public Member Functions

Static Helpers

Check state of lock

static bool locked ()
 Check if the current thread has the lock. More...
 
static PyGILState_STATE acquire ()
 Call PyGILState_Ensure. More...
 
static void release (PyGILState_STATE tstate)
 Call PyGILState_Release. More...
 

Private Member Functions

 GlobalInterpreterLock (const GlobalInterpreterLock &)
 

Private Attributes

PyGILState_STATE m_state
 Current GIL state. More...
 

Detailed Description

Defines a structure for acquiring/releasing the Python GIL using the RAII pattern.

Definition at line 23 of file GlobalInterpreterLock.h.

Constructor & Destructor Documentation

◆ GlobalInterpreterLock() [1/2]

Mantid::PythonInterface::GlobalInterpreterLock::GlobalInterpreterLock ( )

Default constructor.

Ensures this thread is ready to call Python code.

Definition at line 49 of file GlobalInterpreterLock.cpp.

◆ ~GlobalInterpreterLock()

Mantid::PythonInterface::GlobalInterpreterLock::~GlobalInterpreterLock ( )

Destructor.

Resets the Python threadstate to the state before this object was created.

Definition at line 55 of file GlobalInterpreterLock.cpp.

References m_state, and release().

◆ GlobalInterpreterLock() [2/2]

Mantid::PythonInterface::GlobalInterpreterLock::GlobalInterpreterLock ( const GlobalInterpreterLock )
private

Member Function Documentation

◆ acquire()

PyGILState_STATE Mantid::PythonInterface::GlobalInterpreterLock::acquire ( )
static

Call PyGILState_Ensure.

Returns
A handle to the Python threadstate before the acquire() call.

Definition at line 32 of file GlobalInterpreterLock.cpp.

◆ locked()

bool Mantid::PythonInterface::GlobalInterpreterLock::locked ( )
static

Check if the current thread has the lock.

Returns
True if the current thread holds the GIL, false otherwise

Definition at line 20 of file GlobalInterpreterLock.cpp.

◆ release()

void Mantid::PythonInterface::GlobalInterpreterLock::release ( PyGILState_STATE  tstate)
static

Call PyGILState_Release.

There must be have been a call to acquire() to create the tstate value given here.

Parameters
tstateThe Python threadstate returned by the matching call to acquire()

Definition at line 40 of file GlobalInterpreterLock.cpp.

Referenced by ~GlobalInterpreterLock().

Member Data Documentation

◆ m_state

PyGILState_STATE Mantid::PythonInterface::GlobalInterpreterLock::m_state
private

Current GIL state.

Definition at line 43 of file GlobalInterpreterLock.h.

Referenced by ~GlobalInterpreterLock().


The documentation for this class was generated from the following files: