Commit 187aa545 authored by Kristján Valur Jónsson's avatar Kristján Valur Jónsson

Signal condition variables with the mutex held. Destroy condition variables

before their mutexes.
parent 902274e9
...@@ -313,13 +313,14 @@ static void create_gil(void) ...@@ -313,13 +313,14 @@ static void create_gil(void)
static void destroy_gil(void) static void destroy_gil(void)
{ {
MUTEX_FINI(gil_mutex); /* some pthread-like implementations tie the mutex to the cond
#ifdef FORCE_SWITCHING * and must have the cond destroyed first.
MUTEX_FINI(switch_mutex); */
#endif
COND_FINI(gil_cond); COND_FINI(gil_cond);
MUTEX_FINI(gil_mutex);
#ifdef FORCE_SWITCHING #ifdef FORCE_SWITCHING
COND_FINI(switch_cond); COND_FINI(switch_cond);
MUTEX_FINI(switch_mutex);
#endif #endif
_Py_atomic_store_explicit(&gil_locked, -1, _Py_memory_order_release); _Py_atomic_store_explicit(&gil_locked, -1, _Py_memory_order_release);
_Py_ANNOTATE_RWLOCK_DESTROY(&gil_locked); _Py_ANNOTATE_RWLOCK_DESTROY(&gil_locked);
......
...@@ -443,12 +443,15 @@ PyThread_free_lock(PyThread_type_lock lock) ...@@ -443,12 +443,15 @@ PyThread_free_lock(PyThread_type_lock lock)
dprintf(("PyThread_free_lock(%p) called\n", lock)); dprintf(("PyThread_free_lock(%p) called\n", lock));
status = pthread_mutex_destroy( &thelock->mut ); /* some pthread-like implementations tie the mutex to the cond
CHECK_STATUS("pthread_mutex_destroy"); * and must have the cond destroyed first.
*/
status = pthread_cond_destroy( &thelock->lock_released ); status = pthread_cond_destroy( &thelock->lock_released );
CHECK_STATUS("pthread_cond_destroy"); CHECK_STATUS("pthread_cond_destroy");
status = pthread_mutex_destroy( &thelock->mut );
CHECK_STATUS("pthread_mutex_destroy");
free((void *)thelock); free((void *)thelock);
} }
...@@ -531,12 +534,12 @@ PyThread_release_lock(PyThread_type_lock lock) ...@@ -531,12 +534,12 @@ PyThread_release_lock(PyThread_type_lock lock)
thelock->locked = 0; 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 */ /* wake up someone (anyone, if any) waiting on the lock */
status = pthread_cond_signal( &thelock->lock_released ); status = pthread_cond_signal( &thelock->lock_released );
CHECK_STATUS("pthread_cond_signal"); CHECK_STATUS("pthread_cond_signal");
status = pthread_mutex_unlock( &thelock->mut );
CHECK_STATUS("pthread_mutex_unlock[3]");
} }
#endif /* USE_SEMAPHORES */ #endif /* USE_SEMAPHORES */
......
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