From 04ae67db5330c379ab05e91132dd28c517e280c6 Mon Sep 17 00:00:00 2001 From: mread Date: Wed, 30 Nov 2011 13:18:11 +0000 Subject: Reduce unnecessary QtCore DLL loads during Symbian app thread creation The Symbain fast allocator integration in Qt 4.7 loads QtCore.DLL to check availablility. This load has been causing a crash in the Nokia Store app when a different version of QtCore 4.7 is installed. The new DLL is loaded and it's static data tries to initialise before the allocator is set up. This change stores the allocator setup function so that extra DLL loads are not required. Now the same allocator setup function is used for the lifetime of the app. Reviewed-by: Shane Kearns --- src/s60main/newallocator_hook.cpp | 40 +++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/s60main/newallocator_hook.cpp b/src/s60main/newallocator_hook.cpp index 7e0b344..4cec214 100644 --- a/src/s60main/newallocator_hook.cpp +++ b/src/s60main/newallocator_hook.cpp @@ -109,26 +109,38 @@ struct SStdEpocThreadCreateInfo : public SThreadCreateInfo * startup. On return, there is some kind of heap allocator installed on the * thread. */ +typedef int (*TSetupThreadHeapFunc)(TBool aNotFirst, SStdEpocThreadCreateInfo& aInfo); +// keep the SetupThreadHeap() pointer so that we don't reload QtCore.dll after the first time +static TSetupThreadHeapFunc gp_qt_symbian_SetupThreadHeap = 0; +static bool gp_qt_symbian_SetupThreadHeap_set = false; + TInt UserHeap::SetupThreadHeap(TBool aNotFirst, SStdEpocThreadCreateInfo& aInfo) { TInt r = KErrNone; #ifndef __WINS__ - // attempt to create the fast allocator through a known export ordinal in qtcore.dll - RLibrary qtcore; - if (qtcore.Load(QtCoreLibName) == KErrNone) - { - const int qt_symbian_SetupThreadHeap_eabi_ordinal = 3713; - TLibraryFunction libFunc = qtcore.Lookup(qt_symbian_SetupThreadHeap_eabi_ordinal); - if (libFunc) - { - typedef int (*TSetupThreadHeapFunc)(TBool aNotFirst, SStdEpocThreadCreateInfo& aInfo); - TSetupThreadHeapFunc p_qt_symbian_SetupThreadHeap = TSetupThreadHeapFunc(libFunc); - r = (*p_qt_symbian_SetupThreadHeap)(aNotFirst, aInfo); + // on first call, aNotFirst will be false. + // on second call, gp_qt_symbian_SetupThreadHeap_set will be false(!) because WSD is zeroed after the first call + // on subsequent calls, both will be true and we can use the stored SetupThreadHeap() pointer + if (aNotFirst && gp_qt_symbian_SetupThreadHeap_set) { + if (gp_qt_symbian_SetupThreadHeap) + return (*gp_qt_symbian_SetupThreadHeap)(aNotFirst, aInfo); + } else { + // attempt to create the fast allocator through a known export ordinal in qtcore.dll + RLibrary qtcore; + gp_qt_symbian_SetupThreadHeap_set = true; + if (qtcore.Load(QtCoreLibName) == KErrNone) { + const int qt_symbian_SetupThreadHeap_eabi_ordinal = 3713; + TLibraryFunction libFunc = qtcore.Lookup(qt_symbian_SetupThreadHeap_eabi_ordinal); + if (libFunc) { + TSetupThreadHeapFunc p_qt_symbian_SetupThreadHeap = TSetupThreadHeapFunc(libFunc); + gp_qt_symbian_SetupThreadHeap = p_qt_symbian_SetupThreadHeap; + r = (*p_qt_symbian_SetupThreadHeap)(aNotFirst, aInfo); + } + qtcore.Close(); + if (libFunc) + return r; } - qtcore.Close(); - if (libFunc) - return r; } #endif -- cgit v0.12