Fix building with SIMPLE_THREADS=1

This commit is contained in:
rdb 2018-10-16 22:15:36 +02:00
parent 88b0f3327d
commit 90cc8fe385
8 changed files with 37 additions and 25 deletions

View File

@ -62,4 +62,12 @@ default_thread_consider_yield() {
void (*global_thread_yield)() = default_thread_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

View File

@ -233,6 +233,15 @@ INLINE void 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
INLINE void thread_yield() {

View File

@ -752,6 +752,11 @@ PyObject *Dtool_PyModuleInitHelper(LibraryDef *defs[], const char *modulename) {
ExecutionEnvironment::shadow_environment_variable("MAIN_DIR", main_dir.to_os_specific());
PyErr_Clear();
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);

View File

@ -28,7 +28,7 @@ typedef _typeobject PyTypeObject;
typedef struct {} PyStringObject;
typedef struct {} PyUnicodeObject;
class PyThreadState;
typedef struct _ts PyThreadState;
typedef int Py_ssize_t;
typedef struct bufferinfo Py_buffer;

View File

@ -51,14 +51,6 @@ is_threading_supported() {
return true;
}
/**
*
*/
INLINE bool ThreadSimpleImpl::
is_true_threads() {
return (is_os_threads != 0);
}
/**
*
*/

View File

@ -141,8 +141,8 @@ start(ThreadPriority priority, bool joinable) {
#ifdef HAVE_PYTHON
// Query the current Python thread state.
_python_state = PyThreadState_Swap(nullptr);
PyThreadState_Swap(_python_state);
_python_state = thread_state_swap(nullptr);
thread_state_swap(_python_state);
#endif // HAVE_PYTHON
init_thread_context(_context, _stack, _stack_size, st_begin_thread, this);
@ -201,6 +201,14 @@ 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::
begin_thread() {
#ifdef HAVE_PYTHON
PyThreadState_Swap(_python_state);
thread_state_swap(_python_state);
#endif // HAVE_PYTHON
#ifdef HAVE_POSIX_THREADS

View File

@ -63,7 +63,7 @@ public:
INLINE static void bind_thread(Thread *thread);
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 void sleep(double seconds);
INLINE static void yield();

View File

@ -237,7 +237,7 @@ next_context() {
#ifdef HAVE_PYTHON
// Save the current Python thread state.
_current_thread->_python_state = PyThreadState_Swap(nullptr);
_current_thread->_python_state = thread_state_swap(nullptr);
#endif // HAVE_PYTHON
#ifdef DO_PSTATS
@ -258,7 +258,7 @@ next_context() {
#endif // DO_PSTATS
#ifdef HAVE_PYTHON
PyThreadState_Swap(_current_thread->_python_state);
thread_state_swap(_current_thread->_python_state);
#endif // HAVE_PYTHON
}
@ -470,16 +470,6 @@ init_pointers() {
_pointers_initialized = true;
_global_ptr = new ThreadSimpleManager;
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
}
}