summaryrefslogtreecommitdiffstats
path: root/lib/libpthread/thread/thread_malloc_lock.c
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2006-02-22 07:16:31 +0000
committerotto <otto@openbsd.org>2006-02-22 07:16:31 +0000
commit882a3f0680aa778b013f4c220223d00b28019a86 (patch)
tree0862b8b2a97ace2964bdca1d67de26262731407e /lib/libpthread/thread/thread_malloc_lock.c
parentExpect PMU_INT_SNDBRT while resetting the adb bus; although this brings the (diff)
downloadwireguard-openbsd-882a3f0680aa778b013f4c220223d00b28019a86.tar.xz
wireguard-openbsd-882a3f0680aa778b013f4c220223d00b28019a86.zip
Avouid a race in atexit() handling by introducing a lock. Problem
originally reported by Gergely Kovacs; help from dhartmei@; ok tedu@ millert@
Diffstat (limited to 'lib/libpthread/thread/thread_malloc_lock.c')
-rw-r--r--lib/libpthread/thread/thread_malloc_lock.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/libpthread/thread/thread_malloc_lock.c b/lib/libpthread/thread/thread_malloc_lock.c
index 8755b1dad27..6e8b96bb656 100644
--- a/lib/libpthread/thread/thread_malloc_lock.c
+++ b/lib/libpthread/thread/thread_malloc_lock.c
@@ -1,10 +1,11 @@
-/* $OpenBSD: thread_malloc_lock.c,v 1.4 2002/11/05 22:19:55 marc Exp $ */
+/* $OpenBSD: thread_malloc_lock.c,v 1.5 2006/02/22 07:16:32 otto Exp $ */
/* Public Domain <marc@snafu.org> */
#include <pthread.h>
#include "pthread_private.h"
static spinlock_t malloc_lock = _SPINLOCK_INITIALIZER;
+static spinlock_t atexit_lock = _SPINLOCK_INITIALIZER;
void
_thread_malloc_lock()
@@ -22,3 +23,15 @@ void
_thread_malloc_init()
{
}
+
+void
+_thread_atexit_lock()
+{
+ _SPINLOCK(&atexit_lock);
+}
+
+void
+_thread_atexit_unlock()
+{
+ _SPINUNLOCK(&atexit_lock);
+}