diff --git a/headers/private/interface/ColorConversion.h b/headers/private/interface/ColorConversion.h index e1108a93a8..cd96f466b5 100644 --- a/headers/private/interface/ColorConversion.h +++ b/headers/private/interface/ColorConversion.h @@ -50,6 +50,10 @@ public: static status_t InitializeDefault(bool useServer = false); +private: + static void _InitializeDefaultAppServer(); + static void _InitializeDefaultNoAppServer(); + private: const color_map *fColorMap; color_map *fOwnColorMap; diff --git a/src/kits/interface/ColorConversion.cpp b/src/kits/interface/ColorConversion.cpp index 67d70a6717..24ab6abf52 100644 --- a/src/kits/interface/ColorConversion.cpp +++ b/src/kits/interface/ColorConversion.cpp @@ -437,27 +437,38 @@ PaletteConverter::GrayColorForIndex(uint8 index) const } -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); }