diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-06-12 15:19:26 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-06-12 15:30:50 +0300 |
commit | cb409bb219d701af68381eeb2aa4bc027322857d (patch) | |
tree | 47801c32d0509373d61b9d4c0d7603b5601f5be3 /source/blender/blenlib | |
parent | 3b2e19cb4c7a14bf4f76a8470e559409ce837ff5 (diff) |
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.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/rand.c | 15 |
1 files changed, 15 insertions, 0 deletions
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); } |