diff options
author | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2012-06-05 22:17:42 (GMT) |
---|---|---|
committer | Kristján Valur Jónsson <kristjan@ccpgames.com> | 2012-06-05 22:17:42 (GMT) |
commit | 187aa545165d8d5eac222ecce29c8a77e0282dd4 (patch) | |
tree | bd115faeedc479c9e125f8f4202c28ecc2d3e1f7 /Python | |
parent | 902274e9483fb1e179f128b0d5eaafdcae4a4798 (diff) | |
download | cpython-187aa545165d8d5eac222ecce29c8a77e0282dd4.zip cpython-187aa545165d8d5eac222ecce29c8a77e0282dd4.tar.gz cpython-187aa545165d8d5eac222ecce29c8a77e0282dd4.tar.bz2 |
Signal condition variables with the mutex held. Destroy condition variables
before their mutexes.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval_gil.h | 9 | ||||
-rw-r--r-- | Python/thread_pthread.h | 15 |
2 files changed, 14 insertions, 10 deletions
diff --git a/Python/ceval_gil.h b/Python/ceval_gil.h index bf7a350..e7764f2 100644 --- a/Python/ceval_gil.h +++ b/Python/ceval_gil.h @@ -313,13 +313,14 @@ static void create_gil(void) static void destroy_gil(void) { - MUTEX_FINI(gil_mutex); -#ifdef FORCE_SWITCHING - MUTEX_FINI(switch_mutex); -#endif + /* some pthread-like implementations tie the mutex to the cond + * and must have the cond destroyed first. + */ COND_FINI(gil_cond); + MUTEX_FINI(gil_mutex); #ifdef FORCE_SWITCHING COND_FINI(switch_cond); + MUTEX_FINI(switch_mutex); #endif _Py_atomic_store_explicit(&gil_locked, -1, _Py_memory_order_release); _Py_ANNOTATE_RWLOCK_DESTROY(&gil_locked); diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h index 4f9e2c1..5007aaf 100644 --- a/Python/thread_pthread.h +++ b/Python/thread_pthread.h @@ -443,12 +443,15 @@ PyThread_free_lock(PyThread_type_lock lock) dprintf(("PyThread_free_lock(%p) called\n", lock)); - status = pthread_mutex_destroy( &thelock->mut ); - CHECK_STATUS("pthread_mutex_destroy"); - + /* some pthread-like implementations tie the mutex to the cond + * and must have the cond destroyed first. + */ status = pthread_cond_destroy( &thelock->lock_released ); CHECK_STATUS("pthread_cond_destroy"); + status = pthread_mutex_destroy( &thelock->mut ); + CHECK_STATUS("pthread_mutex_destroy"); + free((void *)thelock); } @@ -531,12 +534,12 @@ PyThread_release_lock(PyThread_type_lock lock) thelock->locked = 0; - status = pthread_mutex_unlock( &thelock->mut ); - CHECK_STATUS("pthread_mutex_unlock[3]"); - /* wake up someone (anyone, if any) waiting on the lock */ status = pthread_cond_signal( &thelock->lock_released ); CHECK_STATUS("pthread_cond_signal"); + + status = pthread_mutex_unlock( &thelock->mut ); + CHECK_STATUS("pthread_mutex_unlock[3]"); } #endif /* USE_SEMAPHORES */ |