aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/random.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/random.c b/src/random.c
index c4241362d..bd109e71b 100644
--- a/src/random.c
+++ b/src/random.c
@@ -34,10 +34,6 @@ void sqlite3_randomness(int N, void *pBuf){
unsigned char t;
unsigned char *zBuf = pBuf;
-#ifndef SQLITE_OMIT_AUTOINIT
- if( sqlite3_initialize() ) return;
-#endif
-
/* The "wsdPrng" macro will resolve to the pseudo-random number generator
** state vector. If writable static data is unsupported on the target,
** we have to locate the state vector at run-time. In the more common
@@ -52,13 +48,23 @@ void sqlite3_randomness(int N, void *pBuf){
#endif
#if SQLITE_THREADSAFE
- sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
+ sqlite3_mutex *mutex;
+#endif
+
+#ifndef SQLITE_OMIT_AUTOINIT
+ if( sqlite3_initialize() ) return;
+#endif
+
+#if SQLITE_THREADSAFE
+ mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_PRNG);
sqlite3_mutex_enter(mutex);
#endif
if( N<=0 || pBuf==0 ){
wsdPrng.isInit = 0;
+#if SQLITE_THREADSAFE
sqlite3_mutex_leave(mutex);
+#endif
return;
}