summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2007-07-20 22:34:41 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2007-07-20 22:34:41 +0000
commit8262bfd19a98c81fa1fb30ddd1e2d625f8749230 (patch)
tree79dca975e21cdfa0530735dd6b4dcd50a30371da /lib
parentf26a9fa12a59729d7234abc92315f872dc2bcd02 (diff)
Initialize the locks in key_table. On hppa _SPINLOCK_LOCKED is 0, so an
uninitialized lock ends up in a locked state. This lead to a deadlock if we called pthread_key_create(). ok marc@, kurt@
Diffstat (limited to 'lib')
-rw-r--r--lib/libpthread/uthread/pthread_private.h3
-rw-r--r--lib/libpthread/uthread/uthread_init.c7
-rw-r--r--lib/libpthread/uthread/uthread_spec.c11
3 files changed, 17 insertions, 4 deletions
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h
index d26fc50bf53..1c7b339e9c9 100644
--- a/lib/libpthread/uthread/pthread_private.h
+++ b/lib/libpthread/uthread/pthread_private.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pthread_private.h,v 1.67 2007/06/05 18:11:49 kurt Exp $ */
+/* $OpenBSD: pthread_private.h,v 1.68 2007/07/20 22:34:40 kettenis Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -1166,6 +1166,7 @@ void _thread_kern_sched_state_unlock(enum pthread_state, spinlock_t *,
void _thread_kern_set_timeout(const struct timespec *);
void _thread_kern_sig_defer(void);
void _thread_kern_sig_undefer(void);
+void _thread_key_init(void);
void _thread_kill_siginfo(int);
void _thread_sig_handler(int, siginfo_t *, struct sigcontext *);
int _thread_sig_handle(int, struct sigcontext *);
diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c
index 93f7ec27ad6..d48e1173566 100644
--- a/lib/libpthread/uthread/uthread_init.c
+++ b/lib/libpthread/uthread/uthread_init.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_init.c,v 1.39 2007/06/05 18:11:49 kurt Exp $ */
+/* $OpenBSD: uthread_init.c,v 1.40 2007/07/20 22:34:40 kettenis Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -370,9 +370,12 @@ _thread_init(void)
if (_thread_pfd_table == NULL)
PANIC("Cannot allocate memory for pollfd table");
- /* initialize the fd table */
+ /* Initialize the fd table: */
_thread_fd_init();
+ /* Initialize the key table: */
+ _thread_key_init();
+
/* Initialise the garbage collector mutex and condition variable. */
if (pthread_mutex_init(&_gc_mutex,NULL) != 0 ||
pthread_cond_init(&_gc_cond,NULL) != 0)
diff --git a/lib/libpthread/uthread/uthread_spec.c b/lib/libpthread/uthread/uthread_spec.c
index 41f66a7e1ac..1d6ee001035 100644
--- a/lib/libpthread/uthread/uthread_spec.c
+++ b/lib/libpthread/uthread/uthread_spec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_spec.c,v 1.8 2006/04/02 21:38:57 djm Exp $ */
+/* $OpenBSD: uthread_spec.c,v 1.9 2007/07/20 22:34:40 kettenis Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -43,6 +43,15 @@
/* Static variables: */
static struct pthread_key key_table[PTHREAD_KEYS_MAX];
+void
+_thread_key_init(void)
+{
+ int key;
+
+ for (key = 0; key < PTHREAD_KEYS_MAX; key++)
+ _SPINLOCK_INIT(&key_table[key].lock);
+}
+
int
pthread_key_create(pthread_key_t * key, void (*destructor) (void *))
{