Protect KIID generator from threading
This commit is contained in:
parent
016a98df86
commit
572747a3f9
|
@ -33,8 +33,12 @@
|
||||||
#include <boost/uuid/entropy_error.hpp>
|
#include <boost/uuid/entropy_error.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <wx/log.h>
|
#include <wx/log.h>
|
||||||
|
|
||||||
|
// boost:mt19937 is not thread-safe
|
||||||
|
static std::mutex rng_mutex;
|
||||||
|
|
||||||
// Create only once, as seeding is *very* expensive
|
// Create only once, as seeding is *very* expensive
|
||||||
static boost::mt19937 rng;
|
static boost::mt19937 rng;
|
||||||
|
@ -69,9 +73,14 @@ KIID::KIID()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( createNilUuids )
|
if( createNilUuids )
|
||||||
|
{
|
||||||
m_uuid = nilGenerator();
|
m_uuid = nilGenerator();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock( rng_mutex );
|
||||||
m_uuid = randomGenerator();
|
m_uuid = randomGenerator();
|
||||||
|
}
|
||||||
|
|
||||||
#if BOOST_VERSION >= 106700
|
#if BOOST_VERSION >= 106700
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue