Add utility function to help debugging concurrent usage of global RNG

Checks are disabled by default, but we need to make them enabled by
porting all required areas, or by removing API which uses global RNG.
This commit is contained in:
Sergey Sharybin 2018-06-12 14:19:26 +02:00
parent 3b2e19cb4c
commit cb409bb219
1 changed files with 15 additions and 0 deletions

View File

@ -268,23 +268,38 @@ void BLI_rng_skip(RNG *rng, int n)
/* initialize with some non-zero seed */
static RNG theBLI_rng = {611330372042337130};
static void ensure_rng_thread_safe(void)
{
/* TODO(sergey): Ideally we will get rid of all rng functions which
* are using global generator. But for until then we need some way to
* catch "bad" calls at runtime.
*
* NOTE: Lots of areas are not ported, so we keep check disabled for now.
*/
// BLI_assert(BLI_thread_is_main());
}
void BLI_srandom(unsigned int seed)
{
ensure_rng_thread_safe();
BLI_rng_srandom(&theBLI_rng, seed);
}
int BLI_rand(void)
{
ensure_rng_thread_safe();
return BLI_rng_get_int(&theBLI_rng);
}
float BLI_frand(void)
{
ensure_rng_thread_safe();
return BLI_rng_get_float(&theBLI_rng);
}
void BLI_frand_unit_v3(float v[3])
{
ensure_rng_thread_safe();
BLI_rng_get_float_unit_v3(&theBLI_rng, v);
}