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:
parent
e06f9e35b3
commit
dd93eb88f2
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user