Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
aboutsummaryrefslogtreecommitdiffstats
blob: b5175bd3a0977308e8cd50b43768269d32d98108 (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
44
45
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "gilstate.h"

namespace Shiboken
{

GilState::GilState(bool acquire)
{
    if (acquire && Py_IsInitialized()) {
        m_gstate = PyGILState_Ensure();
        m_locked = true;
    }
}

GilState::~GilState()
{
    release();
}

void GilState::acquire()
{
    if (Py_IsInitialized()) {
        m_gstate = PyGILState_Ensure();
        m_locked = true;
    }
}

void GilState::release()
{
    if (m_locked && Py_IsInitialized()) {
        PyGILState_Release(m_gstate);
        m_locked = false;
    }
}

// Abandon the lock: Only for special situations, like termination of a
// POSIX thread (PYSIDE 1282).
void GilState::abandon()
{
    m_locked = false;
}

} // namespace Shiboken