fixed repeated allocation of RNG on each theRNG() call (thanks to barjenbr for the patch)
This commit is contained in:
parent
0cfcb48796
commit
4b2f9e78fc
@ -689,19 +689,22 @@ RNG& theRNG()
|
||||
#else
|
||||
|
||||
static pthread_key_t tlsRNGKey = 0;
|
||||
static pthread_once_t tlsRNGKeyOnce = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void deleteRNG(void* data)
|
||||
{
|
||||
delete (RNG*)data;
|
||||
}
|
||||
|
||||
static void makeRNGKey()
|
||||
{
|
||||
int errcode = pthread_key_create(&tlsRNGKey, deleteRNG);
|
||||
CV_Assert(errcode == 0);
|
||||
}
|
||||
|
||||
RNG& theRNG()
|
||||
{
|
||||
if( !tlsRNGKey )
|
||||
{
|
||||
int errcode = pthread_key_create(&tlsRNGKey, deleteRNG);
|
||||
CV_Assert(errcode == 0);
|
||||
}
|
||||
pthread_once(&tlsRNGKeyOnce, makeRNGKey);
|
||||
RNG* rng = (RNG*)pthread_getspecific(tlsRNGKey);
|
||||
if( !rng )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user