Commit 4b2f9e78 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

fixed repeated allocation of RNG on each theRNG() call (thanks to barjenbr for the patch)

parent 0cfcb487
...@@ -689,19 +689,22 @@ RNG& theRNG() ...@@ -689,19 +689,22 @@ RNG& theRNG()
#else #else
static pthread_key_t tlsRNGKey = 0; static pthread_key_t tlsRNGKey = 0;
static pthread_once_t tlsRNGKeyOnce = PTHREAD_ONCE_INIT;
static void deleteRNG(void* data) static void deleteRNG(void* data)
{ {
delete (RNG*)data; delete (RNG*)data;
} }
static void makeRNGKey()
{
int errcode = pthread_key_create(&tlsRNGKey, deleteRNG);
CV_Assert(errcode == 0);
}
RNG& theRNG() RNG& theRNG()
{ {
if( !tlsRNGKey ) pthread_once(&tlsRNGKeyOnce, makeRNGKey);
{
int errcode = pthread_key_create(&tlsRNGKey, deleteRNG);
CV_Assert(errcode == 0);
}
RNG* rng = (RNG*)pthread_getspecific(tlsRNGKey); RNG* rng = (RNG*)pthread_getspecific(tlsRNGKey);
if( !rng ) if( !rng )
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment