9595#define MUTEX_INIT (mut ) \
9696 if (pthread_mutex_init(&mut, NULL)) { \
9797 Py_FatalError("pthread_mutex_init(" #mut ") failed"); };
98+ #define MUTEX_FINI (mut ) \
99+ if (pthread_mutex_destroy(&mut)) { \
100+ Py_FatalError("pthread_mutex_destroy(" #mut ") failed"); };
98101#define MUTEX_LOCK (mut ) \
99102 if (pthread_mutex_lock(&mut)) { \
100103 Py_FatalError("pthread_mutex_lock(" #mut ") failed"); };
@@ -106,6 +109,9 @@ do { \
106109#define COND_INIT (cond ) \
107110 if (pthread_cond_init(&cond, NULL)) { \
108111 Py_FatalError("pthread_cond_init(" #cond ") failed"); };
112+ #define COND_FINI (cond ) \
113+ if (pthread_cond_destroy(&cond)) { \
114+ Py_FatalError("pthread_cond_destroy(" #cond ") failed"); };
109115#define COND_SIGNAL (cond ) \
110116 if (pthread_cond_signal(&cond)) { \
111117 Py_FatalError("pthread_cond_signal(" #cond ") failed"); };
@@ -305,9 +311,24 @@ static void create_gil(void)
305311 _Py_atomic_store_explicit (& gil_locked , 0 , _Py_memory_order_release );
306312}
307313
314+ static void destroy_gil (void )
315+ {
316+ MUTEX_FINI (gil_mutex );
317+ #ifdef FORCE_SWITCHING
318+ MUTEX_FINI (switch_mutex );
319+ #endif
320+ COND_FINI (gil_cond );
321+ #ifdef FORCE_SWITCHING
322+ COND_FINI (switch_cond );
323+ #endif
324+ _Py_atomic_store_explicit (& gil_locked , -1 , _Py_memory_order_release );
325+ _Py_ANNOTATE_RWLOCK_DESTROY (& gil_locked );
326+ }
327+
308328static void recreate_gil (void )
309329{
310330 _Py_ANNOTATE_RWLOCK_DESTROY (& gil_locked );
331+ /* XXX should we destroy the old OS resources here? */
311332 create_gil ();
312333}
313334
0 commit comments