diff options
author | Thomas Preud'homme <thomas.preudhomme@arm.com> | 2017-01-30 14:23:00 +0300 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2017-02-14 01:04:17 +0300 |
commit | fa55c610facaae12e38d90d14e44fecd1259b3ab (patch) | |
tree | ce19e155be44925f8bd7ed33b501cc414b47f3d2 /newlib/libc/stdlib | |
parent | af272aca591fe1dc0f1be64ae5bda147ea98a047 (diff) |
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.
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r-- | newlib/libc/stdlib/__call_atexit.c | 2 | ||||
-rw-r--r-- | newlib/libc/stdlib/arc4random.c | 8 | ||||
-rw-r--r-- | newlib/libc/stdlib/arc4random.h | 2 | ||||
-rw-r--r-- | newlib/libc/stdlib/quick_exit.c | 6 |
4 files changed, 18 insertions, 0 deletions
diff --git a/newlib/libc/stdlib/__call_atexit.c b/newlib/libc/stdlib/__call_atexit.c index 7d5e0d046..6a809cc4d 100644 --- a/newlib/libc/stdlib/__call_atexit.c +++ b/newlib/libc/stdlib/__call_atexit.c @@ -11,7 +11,9 @@ /* Make this a weak reference to avoid pulling in free. */ void free(void *) _ATTRIBUTE((__weak__)); +#ifndef __SINGLE_THREAD__ __LOCK_INIT_RECURSIVE(, __atexit_recursive_mutex); +#endif #ifdef _REENT_GLOBAL_ATEXIT struct _atexit *_global_atexit = _NULL; 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 } diff --git a/newlib/libc/stdlib/arc4random.h b/newlib/libc/stdlib/arc4random.h index 3c5fe2353..4b9855305 100644 --- a/newlib/libc/stdlib/arc4random.h +++ b/newlib/libc/stdlib/arc4random.h @@ -47,7 +47,9 @@ #endif /* _ARC4_LOCK_INIT */ +#ifndef __SINGLE_THREAD__ _ARC4_LOCK_INIT +#endif #ifdef _ARC4RANDOM_DATA _ARC4RANDOM_DATA diff --git a/newlib/libc/stdlib/quick_exit.c b/newlib/libc/stdlib/quick_exit.c index aaa5f9f7f..5ab2609bf 100644 --- a/newlib/libc/stdlib/quick_exit.c +++ b/newlib/libc/stdlib/quick_exit.c @@ -44,7 +44,9 @@ struct quick_exit_handler { /** * Lock protecting the handlers list. */ +#ifndef __SINGLE_THREAD__ __LOCK_INIT(static, __at_quick_exit_mutex); +#endif /** * Stack of cleanup handlers. These will be invoked in reverse order when */ @@ -60,10 +62,14 @@ at_quick_exit(void (*func)(void)) if (NULL == h) return (1); h->cleanup = func; +#ifndef __SINGLE_THREAD__ __lock_acquire(__at_quick_exit_mutex); +#endif h->next = handlers; handlers = h; +#ifndef __SINGLE_THREAD__ __lock_release(__at_quick_exit_mutex); +#endif return (0); } |