diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-12 22:56:02 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-12 22:56:02 (GMT) |
commit | a1d23326b19a0182ef74aae32386c5119b1a6e39 (patch) | |
tree | b8f3a29ec4c35c25a08e6d510427a53d73ff8f3b | |
parent | 87e5d347ee10d6c98849609abb6553d6844dbb34 (diff) | |
download | cpython-a1d23326b19a0182ef74aae32386c5119b1a6e39.zip cpython-a1d23326b19a0182ef74aae32386c5119b1a6e39.tar.gz cpython-a1d23326b19a0182ef74aae32386c5119b1a6e39.tar.bz2 |
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.
-rw-r--r-- | Python/ceval_gil.h | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/Python/ceval_gil.h b/Python/ceval_gil.h index bcc4fb9..d4d6fdd 100644 --- a/Python/ceval_gil.h +++ b/Python/ceval_gil.h @@ -106,7 +106,7 @@ do { \ #define COND_INIT(cond) \ if (pthread_cond_init(&cond, NULL)) { \ Py_FatalError("pthread_cond_init(" #cond ") failed"); }; -#define COND_PREPARE(cond) +#define COND_RESET(cond) #define COND_SIGNAL(cond) \ if (pthread_cond_signal(&cond)) { \ Py_FatalError("pthread_cond_signal(" #cond ") failed"); }; @@ -172,7 +172,7 @@ do { \ /* auto-reset, non-signalled */ \ if (!(cond = CreateEvent(NULL, FALSE, FALSE, NULL))) { \ Py_FatalError("CreateMutex(" #cond ") failed"); }; -#define COND_PREPARE(cond) \ +#define COND_RESET(cond) \ if (!ResetEvent(cond)) { \ Py_FatalError("ResetEvent(" #cond ") failed"); }; #define COND_SIGNAL(cond) \ @@ -265,23 +265,21 @@ static void drop_gil(PyThreadState *tstate) MUTEX_LOCK(gil_mutex); gil_locked = 0; COND_SIGNAL(gil_cond); -#ifdef FORCE_SWITCHING - if (gil_drop_request) - COND_PREPARE(switch_cond); -#endif MUTEX_UNLOCK(gil_mutex); #ifdef FORCE_SWITCHING - if (gil_drop_request) { + if (gil_drop_request && tstate != NULL) { MUTEX_LOCK(switch_mutex); /* 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 releasing the mutex, another thread can run through, take the GIL and drop it again, and reset the condition - (COND_PREPARE above) before we even had a chance to wait - for it. */ + before we even had a chance to wait for it. */ COND_WAIT(switch_cond, switch_mutex); + COND_RESET(switch_cond); + } MUTEX_UNLOCK(switch_mutex); } #endif @@ -299,7 +297,7 @@ static void take_gil(PyThreadState *tstate) if (!gil_locked) goto _ready; - COND_PREPARE(gil_cond); + COND_RESET(gil_cond); while (gil_locked) { int timed_out = 0; unsigned long saved_switchnum; |