PythonQt
src
PythonQtThreadSupport.h
Go to the documentation of this file.
1
#pragma once
2
/*
3
*
4
* Copyright (C) 2018 MeVis Medical Solutions AG All Rights Reserved.
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Lesser General Public
8
* License as published by the Free Software Foundation; either
9
* version 2.1 of the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Lesser General Public License for more details.
15
*
16
* Further, this software is distributed without any warranty that it is
17
* free of the rightful claim of any third person regarding infringement
18
* or the like. Any license provided herein, whether implied or
19
* otherwise, applies only to this software file. Patent licenses, if
20
* any, provided herein do not apply to combinations of this program with
21
* other software, or any other product whatsoever.
22
*
23
* You should have received a copy of the GNU Lesser General Public
24
* License along with this library; if not, write to the Free Software
25
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
*
27
* Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
28
* 28359 Bremen, Germany or:
29
*
30
* http://www.mevis.de
31
*
32
*/
33
34
//----------------------------------------------------------------------------------
40
//----------------------------------------------------------------------------------
41
42
#include <QtGlobal>
//Q_DISABLE_COPY
43
#include "
PythonQtPythonInclude.h
"
44
#include "
PythonQtSystem.h
"
45
46
#define PYTHONQT_FULL_THREAD_SUPPORT
47
48
#ifdef PYTHONQT_FULL_THREAD_SUPPORT
49
#define PYTHONQT_GIL_SUPPORT
50
#define PYTHONQT_ALLOW_THREADS_SUPPORT
51
#endif
52
53
#ifdef PYTHONQT_GIL_SUPPORT
54
55
#define PYTHONQT_GIL_SCOPE PythonQtGILScope internal_pythonqt_gilscope;
56
60
class
PYTHONQT_EXPORT
PythonQtGILScope
61
{
62
public
:
63
PythonQtGILScope
();
64
65
~PythonQtGILScope
();
66
67
void
release
();
68
72
static
void
setGILScopeEnabled
(
bool
flag);
74
static
bool
isGILScopeEnabled
();
75
76
private
:
77
PyGILState_STATE _state;
78
bool
_ensured;
79
80
static
bool
_enableGILScope;
81
};
82
83
#else
84
85
#define PYTHONQT_GIL_SCOPE
86
88
class
PythonQtGILScope
89
{
90
public
:
91
PythonQtGILScope
() {}
92
void
release
() {}
93
};
94
95
#endif
96
97
#ifdef PYTHONQT_ALLOW_THREADS_SUPPORT
98
99
#define PYTHONQT_ALLOW_THREADS_SCOPE PythonQtThreadStateSaver internal_pythonqt_savethread;
100
104
class
PythonQtThreadStateSaver
105
{
106
Q_DISABLE_COPY(
PythonQtThreadStateSaver
)
107
public
:
108
PythonQtThreadStateSaver
() {
save
(); }
109
110
~PythonQtThreadStateSaver
() {
restore
(); }
111
112
void
save
() { _state = PyEval_SaveThread(); }
113
114
void
restore
()
115
{
116
if
(_state) {
117
PyEval_RestoreThread(_state);
118
_state =
nullptr
;
119
}
120
}
121
122
private
:
123
PyThreadState* _state;
124
};
125
126
#else
127
128
#define PYTHONQT_ALLOW_THREADS_SCOPE
129
131
class
PythonQtThreadStateSaver
132
{
133
public
:
134
PythonQtThreadStateSaver
() {};
135
void
save
() {}
136
void
restore
() {}
137
};
138
139
#endif
PythonQtPythonInclude.h
PythonQtSystem.h
PYTHONQT_EXPORT
#define PYTHONQT_EXPORT
Definition
PythonQtSystem.h:55
PythonQtGILScope
Definition
PythonQtThreadSupport.h:61
PythonQtGILScope::setGILScopeEnabled
static void setGILScopeEnabled(bool flag)
PythonQtGILScope::~PythonQtGILScope
~PythonQtGILScope()
PythonQtGILScope::release
void release()
PythonQtGILScope::PythonQtGILScope
PythonQtGILScope()
PythonQtGILScope::isGILScopeEnabled
static bool isGILScopeEnabled()
Check if GIL scopes are enabled.
PythonQtThreadStateSaver
Definition
PythonQtThreadSupport.h:105
PythonQtThreadStateSaver::PythonQtThreadStateSaver
PythonQtThreadStateSaver()
Definition
PythonQtThreadSupport.h:108
PythonQtThreadStateSaver::~PythonQtThreadStateSaver
~PythonQtThreadStateSaver()
Definition
PythonQtThreadSupport.h:110
PythonQtThreadStateSaver::restore
void restore()
Definition
PythonQtThreadSupport.h:114
PythonQtThreadStateSaver::save
void save()
Definition
PythonQtThreadSupport.h:112
Generated on
for PythonQt by
1.15.0