Blender V4.3
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
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
30{
31 if (tstate) {
32 PyEval_RestoreThread((PyThreadState *)tstate);
33 }
34}
void * BPy_ThreadStatePtr
Definition BPY_extern.hh:38
void BPY_thread_restore(BPy_ThreadStatePtr tstate)
BPy_ThreadStatePtr BPY_thread_save()