Do not use Q_GLOBAL_STATIC in the implementation of QMutex
Since Q_GLOBAL_STATIC might use QMutex and cause a stack overflow. Task-number: QTBUG-47554 Change-Id: I4853c5e9b9168d4a417200e2a45a1bf9cb103a30 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Pierre Rossi <pierre.rossi@theqtcompany.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
e3d7cf7c96
commit
314c83c0c2
@ -563,7 +563,28 @@ const int FreeListConstants::Sizes[FreeListConstants::BlockCount] = {
|
||||
};
|
||||
|
||||
typedef QFreeList<QMutexPrivate, FreeListConstants> FreeList;
|
||||
Q_GLOBAL_STATIC(FreeList, freelist);
|
||||
// We cannot use Q_GLOBAL_STATIC because it uses QMutex
|
||||
#if defined(Q_COMPILER_THREADSAFE_STATICS)
|
||||
FreeList *freelist()
|
||||
{
|
||||
static FreeList list;
|
||||
return &list;
|
||||
}
|
||||
#else
|
||||
FreeList *freelist()
|
||||
{
|
||||
static QAtomicPointer<FreeList> list;
|
||||
FreeList *local = list.loadAcquire();
|
||||
if (!local) {
|
||||
local = new FreeList;
|
||||
if (!list.testAndSetRelease(0, local)) {
|
||||
delete local;
|
||||
local = list.loadAcquire();
|
||||
}
|
||||
}
|
||||
return local;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
QMutexPrivate *QMutexPrivate::allocate()
|
||||
|
Loading…
x
Reference in New Issue
Block a user