[Bf-blender-cvs] [cb409bb219d] blender2.8: Add utility function to help debugging concurrent usage of global RNG

Sergey Sharybin noreply at git.blender.org
Tue Jun 12 14:31:08 CEST 2018


Commit: cb409bb219d701af68381eeb2aa4bc027322857d
Author: Sergey Sharybin
Date:   Tue Jun 12 14:19:26 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBcb409bb219d701af68381eeb2aa4bc027322857d

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.

===================================================================

M	source/blender/blenlib/intern/rand.c

===================================================================

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);
 }



More information about the Bf-blender-cvs mailing list