Author: bonefish Date: 2009-11-30 12:54:30 +0100 (Mon, 30 Nov 2009) New Revision: 34370 Changeset: http://dev.haiku-os.org/changeset/34370/haiku Modified: haiku/trunk/headers/os/app/Application.h haiku/trunk/src/kits/app/Application.cpp Log: Got rid of the static app resources lock. We use pthread_once() now. Modified: haiku/trunk/headers/os/app/Application.h =================================================================== --- haiku/trunk/headers/os/app/Application.h 2009-11-30 11:42:19 UTC (rev 34369) +++ haiku/trunk/headers/os/app/Application.h 2009-11-30 11:54:30 UTC (rev 34370) @@ -144,8 +144,10 @@ int32 _CountWindows(bool includeMenus) const; BWindow* _WindowAt(uint32 index, bool includeMenus) const; + static void _InitAppResources(); + +private: static BResources* sAppResources; - static BLocker sAppResourcesLock; const char* fAppName; BPrivate::PortLink* fServerLink; Modified: haiku/trunk/src/kits/app/Application.cpp =================================================================== --- haiku/trunk/src/kits/app/Application.cpp 2009-11-30 11:42:19 UTC (rev 34369) +++ haiku/trunk/src/kits/app/Application.cpp 2009-11-30 11:54:30 UTC (rev 34370) @@ -12,6 +12,7 @@ #include <Application.h> #include <new> +#include <pthread.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -43,14 +44,15 @@ #include <ServerMemoryAllocator.h> #include <ServerProtocol.h> + using namespace BPrivate; BApplication *be_app = NULL; BMessenger be_app_messenger; +pthread_once_t sAppResourcesInitOnce = PTHREAD_ONCE_INIT; BResources *BApplication::sAppResources = NULL; -BLocker BApplication::sAppResourcesLock("_app_resources_lock"); enum { @@ -873,40 +875,9 @@ BResources * BApplication::AppResources() { - AutoLocker<BLocker> lock(sAppResourcesLock); + if (sAppResources == NULL) + pthread_once(&sAppResourcesInitOnce, &_InitAppResources); - // BApplication caches its resources, so check - // if it already happened. - if (sAppResources != NULL) - return sAppResources; - - entry_ref ref; - bool found = false; - - // App is already running. Get its entry ref with - // GetAppInfo() - app_info appInfo; - if (be_app && be_app->GetAppInfo(&appInfo) == B_OK) { - ref = appInfo.ref; - found = true; - } else { - // Run() hasn't been called yet - found = BPrivate::get_app_ref(&ref) == B_OK; - } - - if (!found) - return NULL; - - BFile file(&ref, B_READ_ONLY); - if (file.InitCheck() == B_OK) { - sAppResources = new (std::nothrow) BResources(&file, false); - if (sAppResources != NULL - && sAppResources->InitCheck() != B_OK) { - delete sAppResources; - sAppResources = NULL; - } - } - return sAppResources; } @@ -1514,6 +1485,40 @@ } +/*static*/ void +BApplication::_InitAppResources() +{ + entry_ref ref; + bool found = false; + + // App is already running. Get its entry ref with + // GetAppInfo() + app_info appInfo; + if (be_app && be_app->GetAppInfo(&appInfo) == B_OK) { + ref = appInfo.ref; + found = true; + } else { + // Run() hasn't been called yet + found = BPrivate::get_app_ref(&ref) == B_OK; + } + + if (!found) + return; + + BFile file(&ref, B_READ_ONLY); + if (file.InitCheck() != B_OK) + return; + + BResources* resources = new (std::nothrow) BResources(&file, false); + if (resources == NULL || resources->InitCheck() != B_OK) { + delete resources; + return; + } + + sAppResources = resources; +} + + // #pragma mark -