From fa55c610facaae12e38d90d14e44fecd1259b3ab Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 30 Jan 2017 11:23:00 +0000 Subject: Only define static locks in multithreaded mode Newlib build system defines __SINGLE_THREAD__ to allow concurrency code to be only compiled when newlib is configured for multithread. One such example are locks which become useless in single thread mode. Although most static locks are indeed guarded by !defined(__SINGLE_THREAD__), some are not. This commit adds these missing guards to __dd_hash_mutex, __atexit_recursive_mutex, __at_quick_exit_mutex and __arc4random_mutex. It also makes sure locking macros in lock.h are noop in single thread mode. --- newlib/libc/stdlib/arc4random.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'newlib/libc/stdlib/arc4random.c') diff --git a/newlib/libc/stdlib/arc4random.c b/newlib/libc/stdlib/arc4random.c index 75cdff3bc..3cccc3ed4 100644 --- a/newlib/libc/stdlib/arc4random.c +++ b/newlib/libc/stdlib/arc4random.c @@ -180,16 +180,24 @@ arc4random(void) { uint32_t val; +#ifndef __SINGLE_THREAD__ _ARC4_LOCK(); +#endif _rs_random_u32(&val); +#ifndef __SINGLE_THREAD__ _ARC4_UNLOCK(); +#endif return val; } void arc4random_buf(void *buf, size_t n) { +#ifndef __SINGLE_THREAD__ _ARC4_LOCK(); +#endif _rs_random_buf(buf, n); +#ifndef __SINGLE_THREAD__ _ARC4_UNLOCK(); +#endif } -- cgit v1.2.3