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/quick_exit.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'newlib/libc/stdlib/quick_exit.c') 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); } -- cgit v1.2.3