[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haiku-commits
Subject:    [haiku-commits] r34383 - in haiku/trunk: headers/private/interface src/kits/interface
From:       ingo_weinhold () gmx ! de
Date:       2009-11-30 16:26:11
Message-ID: 20091130162611.228C5682D3 () vmsvn ! haiku-os ! org
[Download RAW message or body]

Author: bonefish
Date: 2009-11-30 17:26:10 +0100 (Mon, 30 Nov 2009)
New Revision: 34383
Changeset: http://dev.haiku-os.org/changeset/34383/haiku

Modified:
   haiku/trunk/headers/private/interface/ColorConversion.h
   haiku/trunk/src/kits/interface/ColorConversion.cpp
Log:
Use pthread_once() to guard the initialization of sPaletteConverter. This
changes the semantics slightly: Previously after a failed initialization
another invocation of InitializeDefault() could theoretically initialize the
converter. Since the only error conditions are out of memory and broken app
server connection, this shouldn't really matter, though.


Modified: haiku/trunk/headers/private/interface/ColorConversion.h
===================================================================
--- haiku/trunk/headers/private/interface/ColorConversion.h	2009-11-30 16:10:11 UTC (rev 34382)
+++ haiku/trunk/headers/private/interface/ColorConversion.h	2009-11-30 16:26:10 UTC (rev 34383)
@@ -51,6 +51,10 @@
 	static status_t InitializeDefault(bool useServer = false);
 
 private:
+	static void _InitializeDefaultAppServer();
+	static void _InitializeDefaultNoAppServer();
+
+private:
 	const color_map	*fColorMap;
 	color_map		*fOwnColorMap;
 	status_t		fCStatus;

Modified: haiku/trunk/src/kits/interface/ColorConversion.cpp
===================================================================
--- haiku/trunk/src/kits/interface/ColorConversion.cpp	2009-11-30 16:10:11 UTC (rev 34382)
+++ haiku/trunk/src/kits/interface/ColorConversion.cpp	2009-11-30 16:26:10 UTC (rev 34383)
@@ -437,30 +437,41 @@
 }
 
 
-static BLocker		sPaletteConverterLock("PalConvLock");
+static pthread_once_t sPaletteConverterInitOnce = PTHREAD_ONCE_INIT;
 static PaletteConverter	sPaletteConverter;
 
 
 /*!	\brief Initialize the global instance of PaletteConverter using the system color palette.
 	\return B_OK.
 */
-/* static */
-status_t
+/*static*/ status_t
 PaletteConverter::InitializeDefault(bool useServer)
 {
-	if (sPaletteConverterLock.Lock()) {
-		if (sPaletteConverter.InitCheck() != B_OK) {
-			if (useServer)
-				sPaletteConverter.SetTo(system_colors());
-			else
-				sPaletteConverter.SetTo(kSystemPalette);
-		}
-		sPaletteConverterLock.Unlock();
+	if (sPaletteConverter.InitCheck() != B_OK) {
+		pthread_once(&sPaletteConverterInitOnce,
+			useServer
+				? &_InitializeDefaultAppServer
+				: &_InitializeDefaultNoAppServer);
 	}
-	return B_OK;
+
+	return sPaletteConverter.InitCheck();
 }
 
 
+/*static*/ void
+PaletteConverter::_InitializeDefaultAppServer()
+{
+	sPaletteConverter.SetTo(system_colors());
+}
+
+
+/*static*/ void
+PaletteConverter::_InitializeDefaultNoAppServer()
+{
+	sPaletteConverter.SetTo(kSystemPalette);
+}
+
+
 typedef uint32 (readFunc)(const uint8 **source, int32 index);
 typedef void (writeFunc)(uint8 **dest, uint8 *data, int32 index);
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic