Blender
V4.3
source
blender
python
generic
bpy_threads.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
12
#include <Python.h>
13
14
#include "
../BPY_extern.hh
"
15
16
BPy_ThreadStatePtr
BPY_thread_save
()
17
{
18
/* Use `_PyThreadState_UncheckedGet()` instead of `PyThreadState_Get()`, to avoid a fatal error
19
* issued when a thread state is nullptr (the thread state can be nullptr when quitting Blender).
20
*
21
* `PyEval_SaveThread()` will release the GIL, so this thread has to have the GIL to begin with
22
* or badness will ensue. */
23
if
(_PyThreadState_UncheckedGet() && PyGILState_Check()) {
24
return
(
BPy_ThreadStatePtr
)PyEval_SaveThread();
25
}
26
return
nullptr
;
27
}
28
29
void
BPY_thread_restore
(
BPy_ThreadStatePtr
tstate)
30
{
31
if
(tstate) {
32
PyEval_RestoreThread((PyThreadState *)tstate);
33
}
34
}
BPY_extern.hh
BPy_ThreadStatePtr
void * BPy_ThreadStatePtr
Definition
BPY_extern.hh:38
BPY_thread_restore
void BPY_thread_restore(BPy_ThreadStatePtr tstate)
Definition
bpy_threads.cc:29
BPY_thread_save
BPy_ThreadStatePtr BPY_thread_save()
Definition
bpy_threads.cc:16
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0