Ensure sglog() singleton is threadsafe.

Slightly simplistic, but definitiely correct, method
for ensuring singleton creation is threadsafe. Can
be optimised if lock contention is ever an issue.
This commit is contained in:
James Turner 2013-09-04 08:32:05 +01:00
parent e06f9e35b3
commit dd93eb88f2

View File

@ -348,6 +348,13 @@ sglog()
{
// Force initialization of cerr.
static std::ios_base::Init initializer;
// http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
// in the absence of portable memory barrier ops in Simgear,
// let's keep this correct & safe
static SGMutex m;
SGGuard<SGMutex> g(m);
if( !global_logstream )
global_logstream = new logstream();
return *global_logstream;