From 879f9a0937b437047ca147ec3091efc656e9df6a Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Mon, 30 Nov 2009 11:54:30 +0000 Subject: [PATCH] Got rid of the static app resources lock. We use pthread_once() now. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34370 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/app/Application.h | 4 +- src/kits/app/Application.cpp | 73 +++++++++++++++++++----------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/headers/os/app/Application.h b/headers/os/app/Application.h index f53ed94153..6bcdefac5a 100644 --- a/headers/os/app/Application.h +++ b/headers/os/app/Application.h @@ -144,8 +144,10 @@ private: 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; diff --git a/src/kits/app/Application.cpp b/src/kits/app/Application.cpp index b8be3428c1..2df2202dc8 100644 --- a/src/kits/app/Application.cpp +++ b/src/kits/app/Application.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -43,14 +44,15 @@ #include #include + 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,39 +875,8 @@ BApplication::GetAppInfo(app_info *info) const BResources * BApplication::AppResources() { - AutoLocker lock(sAppResourcesLock); - - // 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; - } - } + if (sAppResources == NULL) + pthread_once(&sAppResourcesInitOnce, &_InitAppResources); return sAppResources; } @@ -1514,6 +1485,40 @@ BApplication::_WindowAt(uint32 index, bool includeMenus) const } +/*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 -