mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 09:52:27 -04:00
Fix building with SIMPLE_THREADS=1
This commit is contained in:
parent
88b0f3327d
commit
90cc8fe385
@ -62,4 +62,12 @@ default_thread_consider_yield() {
|
|||||||
void (*global_thread_yield)() = default_thread_yield;
|
void (*global_thread_yield)() = default_thread_yield;
|
||||||
void (*global_thread_consider_yield)() = default_thread_consider_yield;
|
void (*global_thread_consider_yield)() = default_thread_consider_yield;
|
||||||
|
|
||||||
|
#ifdef HAVE_PYTHON
|
||||||
|
static PyThreadState *
|
||||||
|
default_thread_state_swap(PyThreadState *state) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
PyThreadState *(*global_thread_state_swap)(PyThreadState *tstate) = default_thread_state_swap;
|
||||||
|
#endif // HAVE_PYTHON
|
||||||
|
|
||||||
#endif // HAVE_THREADS && SIMPLE_THREADS
|
#endif // HAVE_THREADS && SIMPLE_THREADS
|
||||||
|
@ -233,6 +233,15 @@ INLINE void thread_consider_yield() {
|
|||||||
(*global_thread_consider_yield)();
|
(*global_thread_consider_yield)();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_PYTHON
|
||||||
|
typedef struct _ts PyThreadState;
|
||||||
|
extern EXPCL_DTOOL_DTOOLBASE PyThreadState *(*global_thread_state_swap)(PyThreadState *tstate);
|
||||||
|
|
||||||
|
INLINE PyThreadState *thread_state_swap(PyThreadState *tstate) {
|
||||||
|
return (*global_thread_state_swap)(tstate);
|
||||||
|
}
|
||||||
|
#endif // HAVE_PYTHON
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
INLINE void thread_yield() {
|
INLINE void thread_yield() {
|
||||||
|
@ -752,6 +752,11 @@ PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], const char *modulename) {
|
|||||||
ExecutionEnvironment::shadow_environment_variable("MAIN_DIR", main_dir.to_os_specific());
|
ExecutionEnvironment::shadow_environment_variable("MAIN_DIR", main_dir.to_os_specific());
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
initialized_main_dir = true;
|
initialized_main_dir = true;
|
||||||
|
|
||||||
|
// Also, while we are at it, initialize the thread swap hook.
|
||||||
|
#if defined(HAVE_THREADS) && defined(SIMPLE_THREADS)
|
||||||
|
global_thread_state_swap = PyThreadState_Swap;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
PyModule_AddIntConstant(module, "Dtool_PyNativeInterface", 1);
|
PyModule_AddIntConstant(module, "Dtool_PyNativeInterface", 1);
|
||||||
|
@ -28,7 +28,7 @@ typedef _typeobject PyTypeObject;
|
|||||||
typedef struct {} PyStringObject;
|
typedef struct {} PyStringObject;
|
||||||
typedef struct {} PyUnicodeObject;
|
typedef struct {} PyUnicodeObject;
|
||||||
|
|
||||||
class PyThreadState;
|
typedef struct _ts PyThreadState;
|
||||||
typedef int Py_ssize_t;
|
typedef int Py_ssize_t;
|
||||||
typedef struct bufferinfo Py_buffer;
|
typedef struct bufferinfo Py_buffer;
|
||||||
|
|
||||||
|
@ -51,14 +51,6 @@ is_threading_supported() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
INLINE bool ThreadSimpleImpl::
|
|
||||||
is_true_threads() {
|
|
||||||
return (is_os_threads != 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -141,8 +141,8 @@ start(ThreadPriority priority, bool joinable) {
|
|||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
// Query the current Python thread state.
|
// Query the current Python thread state.
|
||||||
_python_state = PyThreadState_Swap(nullptr);
|
_python_state = thread_state_swap(nullptr);
|
||||||
PyThreadState_Swap(_python_state);
|
thread_state_swap(_python_state);
|
||||||
#endif // HAVE_PYTHON
|
#endif // HAVE_PYTHON
|
||||||
|
|
||||||
init_thread_context(_context, _stack, _stack_size, st_begin_thread, this);
|
init_thread_context(_context, _stack, _stack_size, st_begin_thread, this);
|
||||||
@ -201,6 +201,14 @@ prepare_for_exit() {
|
|||||||
manager->prepare_for_exit();
|
manager->prepare_for_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool ThreadSimpleImpl::
|
||||||
|
is_true_threads() {
|
||||||
|
return (is_os_threads != 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -238,7 +246,7 @@ st_begin_thread(void *data) {
|
|||||||
void ThreadSimpleImpl::
|
void ThreadSimpleImpl::
|
||||||
begin_thread() {
|
begin_thread() {
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
PyThreadState_Swap(_python_state);
|
thread_state_swap(_python_state);
|
||||||
#endif // HAVE_PYTHON
|
#endif // HAVE_PYTHON
|
||||||
|
|
||||||
#ifdef HAVE_POSIX_THREADS
|
#ifdef HAVE_POSIX_THREADS
|
||||||
|
@ -63,7 +63,7 @@ public:
|
|||||||
|
|
||||||
INLINE static void bind_thread(Thread *thread);
|
INLINE static void bind_thread(Thread *thread);
|
||||||
INLINE static bool is_threading_supported();
|
INLINE static bool is_threading_supported();
|
||||||
INLINE static bool is_true_threads();
|
static bool is_true_threads();
|
||||||
INLINE static bool is_simple_threads();
|
INLINE static bool is_simple_threads();
|
||||||
INLINE static void sleep(double seconds);
|
INLINE static void sleep(double seconds);
|
||||||
INLINE static void yield();
|
INLINE static void yield();
|
||||||
|
@ -237,7 +237,7 @@ next_context() {
|
|||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
// Save the current Python thread state.
|
// Save the current Python thread state.
|
||||||
_current_thread->_python_state = PyThreadState_Swap(nullptr);
|
_current_thread->_python_state = thread_state_swap(nullptr);
|
||||||
#endif // HAVE_PYTHON
|
#endif // HAVE_PYTHON
|
||||||
|
|
||||||
#ifdef DO_PSTATS
|
#ifdef DO_PSTATS
|
||||||
@ -258,7 +258,7 @@ next_context() {
|
|||||||
#endif // DO_PSTATS
|
#endif // DO_PSTATS
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
PyThreadState_Swap(_current_thread->_python_state);
|
thread_state_swap(_current_thread->_python_state);
|
||||||
#endif // HAVE_PYTHON
|
#endif // HAVE_PYTHON
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -470,16 +470,6 @@ init_pointers() {
|
|||||||
_pointers_initialized = true;
|
_pointers_initialized = true;
|
||||||
_global_ptr = new ThreadSimpleManager;
|
_global_ptr = new ThreadSimpleManager;
|
||||||
Thread::get_main_thread();
|
Thread::get_main_thread();
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
|
||||||
// Ensure that the Python threading system is initialized and ready to go.
|
|
||||||
|
|
||||||
#if PY_VERSION_HEX >= 0x03020000
|
|
||||||
Py_Initialize();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PyEval_InitThreads();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user