diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-13 14:16:46 +0000 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-09-13 14:16:46 +0000 |
commit | 64b32a2e48eecce58447ae9f0c678464720eb960 (patch) | |
tree | f10b752b6e1ccb5c2d566ce0c2f8395e56e1ee9e /Python/ceval_gil.h | |
parent | eda372fa5744b71b6b43c810ac0f4f0e88e2d3c6 (diff) | |
download | cpython-64b32a2e48eecce58447ae9f0c678464720eb960.tar.gz |
Issue #9828: Destroy the GIL in Py_Finalize(), so that it gets properly
re-created on a subsequent call to Py_Initialize(). The problem (a crash)
wouldn't appear in 3.1 or 2.7 where the GIL's structure is more trivial.
Diffstat (limited to 'Python/ceval_gil.h')
-rw-r--r-- | Python/ceval_gil.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/Python/ceval_gil.h b/Python/ceval_gil.h index 7d72016083..40e45f75f2 100644 --- a/Python/ceval_gil.h +++ b/Python/ceval_gil.h @@ -95,6 +95,9 @@ do { \ #define MUTEX_INIT(mut) \ if (pthread_mutex_init(&mut, NULL)) { \ Py_FatalError("pthread_mutex_init(" #mut ") failed"); }; +#define MUTEX_FINI(mut) \ + if (pthread_mutex_destroy(&mut)) { \ + Py_FatalError("pthread_mutex_destroy(" #mut ") failed"); }; #define MUTEX_LOCK(mut) \ if (pthread_mutex_lock(&mut)) { \ Py_FatalError("pthread_mutex_lock(" #mut ") failed"); }; @@ -106,6 +109,9 @@ do { \ #define COND_INIT(cond) \ if (pthread_cond_init(&cond, NULL)) { \ Py_FatalError("pthread_cond_init(" #cond ") failed"); }; +#define COND_FINI(cond) \ + if (pthread_cond_destroy(&cond)) { \ + Py_FatalError("pthread_cond_destroy(" #cond ") failed"); }; #define COND_SIGNAL(cond) \ if (pthread_cond_signal(&cond)) { \ Py_FatalError("pthread_cond_signal(" #cond ") failed"); }; @@ -305,9 +311,24 @@ static void create_gil(void) _Py_atomic_store_explicit(&gil_locked, 0, _Py_memory_order_release); } +static void destroy_gil(void) +{ + MUTEX_FINI(gil_mutex); +#ifdef FORCE_SWITCHING + MUTEX_FINI(switch_mutex); +#endif + COND_FINI(gil_cond); +#ifdef FORCE_SWITCHING + COND_FINI(switch_cond); +#endif + _Py_atomic_store_explicit(&gil_locked, -1, _Py_memory_order_release); + _Py_ANNOTATE_RWLOCK_DESTROY(&gil_locked); +} + static void recreate_gil(void) { _Py_ANNOTATE_RWLOCK_DESTROY(&gil_locked); + /* XXX should we destroy the old OS resources here? */ create_gil(); } |