diff options
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/qthreadinstance_p.h | 2 | ||||
-rw-r--r-- | src/tools/qthreadstorage_unix.cpp | 17 |
2 files changed, 19 insertions, 0 deletions
diff --git a/src/tools/qthreadinstance_p.h b/src/tools/qthreadinstance_p.h index 14f0de59..076c2ba1 100644 --- a/src/tools/qthreadinstance_p.h +++ b/src/tools/qthreadinstance_p.h @@ -100,6 +100,8 @@ public: static void finish( TQThreadInstance * ); #endif // Q_OS_WIN32 + static void finishGuiThread( TQThreadInstance *d ); + TQEventLoop* eventLoop; int cleanupType; bool disableThreadPostedEvents : 1; diff --git a/src/tools/qthreadstorage_unix.cpp b/src/tools/qthreadstorage_unix.cpp index d53f6fb6..86192868 100644 --- a/src/tools/qthreadstorage_unix.cpp +++ b/src/tools/qthreadstorage_unix.cpp @@ -38,6 +38,8 @@ #ifdef TQT_THREAD_SUPPORT +#include "ntqapplication.h" +#include "ntqthread.h" #include "qplatformdefs.h" #include "ntqthreadstorage.h" @@ -88,6 +90,21 @@ TQThreadStorageData::TQThreadStorageData( void (*func)( void * ) ) TQThreadStorageData::~TQThreadStorageData() { + // The Gui thread has static storage duration, TQThreadStorage are almost always static (it's + // technically possible to allocate those in the heap, but it's quite unusual). It's impossible + // to predict whichever of those one gets destroyed first, but usually it's a TQThreadStorage. + // In that case we have to do the cleanup of its storage ourself as it won't be possible after + // nullifying the destructor below. + TQThread *guiThread = TQApplication::guiThread(); + if (guiThread) { + TQThreadInstance *d = guiThread->d; + TQMutexLocker locker( d->mutex() ); + if (d->thread_storage && d->thread_storage[id]) { + thread_storage_usage[id].func( d->thread_storage[id] ); + d->thread_storage[id] = nullptr; + } + } + pthread_mutex_lock( &thread_storage_mutex ); thread_storage_usage[id].used = FALSE; thread_storage_usage[id].func = 0; |