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. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34383 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
be62abafab
commit
015943d78f
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user