Kaydet (Commit) a1d23326 authored tarafından Antoine Pitrou's avatar Antoine Pitrou

Try to strengthen condition-waiting under Windows.

If it doesn't work (doesn't solve erratic freezes) we'll have to resort
to tougher (Windows-only) measures.
üst 87e5d347
...@@ -106,7 +106,7 @@ do { \ ...@@ -106,7 +106,7 @@ do { \
#define COND_INIT(cond) \ #define COND_INIT(cond) \
if (pthread_cond_init(&cond, NULL)) { \ if (pthread_cond_init(&cond, NULL)) { \
Py_FatalError("pthread_cond_init(" #cond ") failed"); }; Py_FatalError("pthread_cond_init(" #cond ") failed"); };
#define COND_PREPARE(cond) #define COND_RESET(cond)
#define COND_SIGNAL(cond) \ #define COND_SIGNAL(cond) \
if (pthread_cond_signal(&cond)) { \ if (pthread_cond_signal(&cond)) { \
Py_FatalError("pthread_cond_signal(" #cond ") failed"); }; Py_FatalError("pthread_cond_signal(" #cond ") failed"); };
...@@ -172,7 +172,7 @@ do { \ ...@@ -172,7 +172,7 @@ do { \
/* auto-reset, non-signalled */ \ /* auto-reset, non-signalled */ \
if (!(cond = CreateEvent(NULL, FALSE, FALSE, NULL))) { \ if (!(cond = CreateEvent(NULL, FALSE, FALSE, NULL))) { \
Py_FatalError("CreateMutex(" #cond ") failed"); }; Py_FatalError("CreateMutex(" #cond ") failed"); };
#define COND_PREPARE(cond) \ #define COND_RESET(cond) \
if (!ResetEvent(cond)) { \ if (!ResetEvent(cond)) { \
Py_FatalError("ResetEvent(" #cond ") failed"); }; Py_FatalError("ResetEvent(" #cond ") failed"); };
#define COND_SIGNAL(cond) \ #define COND_SIGNAL(cond) \
...@@ -265,23 +265,21 @@ static void drop_gil(PyThreadState *tstate) ...@@ -265,23 +265,21 @@ static void drop_gil(PyThreadState *tstate)
MUTEX_LOCK(gil_mutex); MUTEX_LOCK(gil_mutex);
gil_locked = 0; gil_locked = 0;
COND_SIGNAL(gil_cond); COND_SIGNAL(gil_cond);
#ifdef FORCE_SWITCHING
if (gil_drop_request)
COND_PREPARE(switch_cond);
#endif
MUTEX_UNLOCK(gil_mutex); MUTEX_UNLOCK(gil_mutex);
#ifdef FORCE_SWITCHING #ifdef FORCE_SWITCHING
if (gil_drop_request) { if (gil_drop_request && tstate != NULL) {
MUTEX_LOCK(switch_mutex); MUTEX_LOCK(switch_mutex);
/* Not switched yet => wait */ /* Not switched yet => wait */
if (gil_last_holder == tstate) if (gil_last_holder == tstate) {
RESET_GIL_DROP_REQUEST();
/* NOTE: if COND_WAIT does not atomically start waiting when /* NOTE: if COND_WAIT does not atomically start waiting when
releasing the mutex, another thread can run through, take releasing the mutex, another thread can run through, take
the GIL and drop it again, and reset the condition the GIL and drop it again, and reset the condition
(COND_PREPARE above) before we even had a chance to wait before we even had a chance to wait for it. */
for it. */
COND_WAIT(switch_cond, switch_mutex); COND_WAIT(switch_cond, switch_mutex);
COND_RESET(switch_cond);
}
MUTEX_UNLOCK(switch_mutex); MUTEX_UNLOCK(switch_mutex);
} }
#endif #endif
...@@ -299,7 +297,7 @@ static void take_gil(PyThreadState *tstate) ...@@ -299,7 +297,7 @@ static void take_gil(PyThreadState *tstate)
if (!gil_locked) if (!gil_locked)
goto _ready; goto _ready;
COND_PREPARE(gil_cond); COND_RESET(gil_cond);
while (gil_locked) { while (gil_locked) {
int timed_out = 0; int timed_out = 0;
unsigned long saved_switchnum; unsigned long saved_switchnum;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment