Signal condition variables with the mutex held. Destroy condition va… · python/cpython@187aa54 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -313,13 +313,14 @@ static void create_gil(void)
313 313
314 314 static void destroy_gil(void)
315 315 {
316 -MUTEX_FINI(gil_mutex);
317 -#ifdef FORCE_SWITCHING
318 -MUTEX_FINI(switch_mutex);
319 -#endif
316 +/* some pthread-like implementations tie the mutex to the cond
317 + * and must have the cond destroyed first.
318 + */
320 319 COND_FINI(gil_cond);
320 +MUTEX_FINI(gil_mutex);
321 321 #ifdef FORCE_SWITCHING
322 322 COND_FINI(switch_cond);
323 +MUTEX_FINI(switch_mutex);
323 324 #endif
324 325 _Py_atomic_store_explicit(&gil_locked, -1, _Py_memory_order_release);
325 326 _Py_ANNOTATE_RWLOCK_DESTROY(&gil_locked);
Original file line number Diff line number Diff line change
@@ -443,12 +443,15 @@ PyThread_free_lock(PyThread_type_lock lock)
443 443
444 444 dprintf(("PyThread_free_lock(%p) called\n", lock));
445 445
446 -status = pthread_mutex_destroy( &thelock->mut );
447 -CHECK_STATUS("pthread_mutex_destroy");
448 -
446 +/* some pthread-like implementations tie the mutex to the cond
447 + * and must have the cond destroyed first.
448 + */
449 449 status = pthread_cond_destroy( &thelock->lock_released );
450 450 CHECK_STATUS("pthread_cond_destroy");
451 451
452 +status = pthread_mutex_destroy( &thelock->mut );
453 +CHECK_STATUS("pthread_mutex_destroy");
454 +
452 455 free((void *)thelock);
453 456 }
454 457
@@ -531,12 +534,12 @@ PyThread_release_lock(PyThread_type_lock lock)
531 534
532 535 thelock->locked = 0;
533 536
534 -status = pthread_mutex_unlock( &thelock->mut );
535 -CHECK_STATUS("pthread_mutex_unlock[3]");
536 -
537 537 /* wake up someone (anyone, if any) waiting on the lock */
538 538 status = pthread_cond_signal( &thelock->lock_released );
539 539 CHECK_STATUS("pthread_cond_signal");
540 +
541 +status = pthread_mutex_unlock( &thelock->mut );
542 +CHECK_STATUS("pthread_mutex_unlock[3]");
540 543 }
541 544
542 545 #endif /* USE_SEMAPHORES */