From 4fd8f368eac1941fc75f11423465ec00377d9aa4 Mon Sep 17 00:00:00 2001 From: Marko Valtanen Date: Tue, 10 Jan 2012 17:29:37 +0200 Subject: Revert "Don't destroy Qt's internal pthread_key_t if it was not initialized" This reverts commit 8c31c6529935cd9ee6f99bc38cfd182d5b3182e2 due to a regression in the QThreadStorage autotest. Fix the problem another way: call pthread_once() in the destructor function to ensure that we always call pthread_key_delete() on a key we created. --- src/corelib/thread/qthread_unix.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/corelib/thread/qthread_unix.cpp b/src/corelib/thread/qthread_unix.cpp index 87979c4032..5fdc799086 100644 --- a/src/corelib/thread/qthread_unix.cpp +++ b/src/corelib/thread/qthread_unix.cpp @@ -150,17 +150,16 @@ static void destroy_current_thread_data(void *p) static void create_current_thread_data_key() { pthread_key_create(¤t_thread_data_key, destroy_current_thread_data); - static class destroy_current_thread_data_key - { - public: - ~destroy_current_thread_data_key() - { - pthread_key_delete(current_thread_data_key); - } - } d; - Q_UNUSED(d); } +static void destroy_current_thread_data_key() +{ + pthread_once(¤t_thread_data_once, create_current_thread_data_key); + pthread_key_delete(current_thread_data_key); +} +Q_DESTRUCTOR_FUNCTION(destroy_current_thread_data_key) + + // Utility functions for getting, setting and clearing thread specific data. // In Symbian, TLS access is significantly faster than pthread_getspecific. // However Symbian does not have the thread destruction cleanup functionality -- cgit v1.2.3