From cb409bb219d701af68381eeb2aa4bc027322857d Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 12 Jun 2018 14:19:26 +0200 Subject: 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. --- source/blender/blenlib/intern/rand.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source/blender') diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index 700524965f0..8d6f55c9ae5 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -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); } -- cgit v1.2.3