summaryrefslogtreecommitdiff
path: root/python/gras/GRAS_Utils.i
blob: afe33141e6b438f9f8c7d48c473b5b94b9bd3f1c (plain)
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
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.

////////////////////////////////////////////////////////////////////////
// Simple class to deal with smart locking/unlocking of python GIL
////////////////////////////////////////////////////////////////////////
%{

struct PyGILPhondler
{
    PyGILPhondler(void):
        s(PyGILState_Ensure())
    {
        //NOP
    }
    ~PyGILPhondler(void)
    {
        PyGILState_Release(s);
    }
    PyGILState_STATE s;
};

%}

////////////////////////////////////////////////////////////////////////
// Simple class to deal with smart save/restore of python thread state
////////////////////////////////////////////////////////////////////////
%{

struct PyTSPhondler
{
    PyTSPhondler(void):
        s(PyEval_SaveThread())
    {
        //NOP
    }
    ~PyTSPhondler(void)
    {
        PyEval_RestoreThread(s);
    }
    PyThreadState *s;
};

%}