summaryrefslogtreecommitdiffstats
path: root/lib/libpthread
diff options
context:
space:
mode:
authormarc <marc@openbsd.org>2004-06-07 21:11:23 +0000
committermarc <marc@openbsd.org>2004-06-07 21:11:23 +0000
commitf91de67f292fa8f5ed29aa37e5f5b87d8645664d (patch)
treedab54fdaea4206ab36fc68dc883c9be239ea81d6 /lib/libpthread
parentCorrectly handle an unaligned long long parameter on stack in varargs functions; (diff)
downloadwireguard-openbsd-f91de67f292fa8f5ed29aa37e5f5b87d8645664d.tar.xz
wireguard-openbsd-f91de67f292fa8f5ed29aa37e5f5b87d8645664d.zip
major bump to libc and libpthread to break the dependency of a
particular implementation of libpthread for libc. libc no longer needs pthread.h to compile. OK millert@, brad@, tedu@
Diffstat (limited to 'lib/libpthread')
-rw-r--r--lib/libpthread/shlib_version2
-rw-r--r--lib/libpthread/thread/Makefile.inc4
-rw-r--r--lib/libpthread/thread/thread_storage.c82
-rw-r--r--lib/libpthread/thread/thread_tag.c120
-rw-r--r--lib/libpthread/uthread/pthread_private.h4
-rw-r--r--lib/libpthread/uthread/uthread_fd.c43
-rw-r--r--lib/libpthread/uthread/uthread_file.c13
-rw-r--r--lib/libpthread/uthread/uthread_init.c9
8 files changed, 142 insertions, 135 deletions
diff --git a/lib/libpthread/shlib_version b/lib/libpthread/shlib_version
index 012c14171d3..d9961ea9fef 100644
--- a/lib/libpthread/shlib_version
+++ b/lib/libpthread/shlib_version
@@ -1,2 +1,2 @@
-major=3
+major=4
minor=0
diff --git a/lib/libpthread/thread/Makefile.inc b/lib/libpthread/thread/Makefile.inc
index 074139f176b..2545995b494 100644
--- a/lib/libpthread/thread/Makefile.inc
+++ b/lib/libpthread/thread/Makefile.inc
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile.inc,v 1.5 2003/01/20 18:12:11 marc Exp $
+# $OpenBSD: Makefile.inc,v 1.6 2004/06/07 21:11:23 marc Exp $
.PATH: ${SRCDIR}/thread
-SRCS+= thread_storage.c thread_malloc_lock.c
+SRCS+= thread_tag.c thread_malloc_lock.c
diff --git a/lib/libpthread/thread/thread_storage.c b/lib/libpthread/thread/thread_storage.c
deleted file mode 100644
index 61609f9c277..00000000000
--- a/lib/libpthread/thread/thread_storage.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/* $OpenBSD: thread_storage.c,v 1.6 2002/11/05 22:19:55 marc Exp $ */
-/* Public Domain */
-
-/*
- * libpthread's stronger functions
- */
-
-#include <stdlib.h>
-#include <pthread.h>
-#include <string.h>
-#include "pthread_private.h"
-
-void
-_libc_private_storage_lock(mutex)
- pthread_mutex_t *mutex;
-{
- if (__isthreaded && pthread_mutex_lock(mutex) != 0)
- PANIC("_libc_private_storage_lock");
-}
-
-void
-_libc_private_storage_unlock(mutex)
- pthread_mutex_t *mutex;
-{
- if (__isthreaded && pthread_mutex_unlock(mutex) != 0)
- PANIC("_libc_private_storage_unlock");
-}
-
-void *
-_libc_private_storage(volkey, init, initsz, error)
- volatile struct _thread_private_key_struct * volkey;
- void * init;
- size_t initsz;
- void * error;
-{
- void *result;
- void (*cleanfn)(void *);
- struct _thread_private_key_struct * key;
-
- /* Use static storage while not threaded: */
- if (!__isthreaded)
- return init;
-
- key = (struct _thread_private_key_struct *)volkey; /* for gcc */
-
- /* Create the key once: */
- if (volkey->once.state == PTHREAD_NEEDS_INIT) {
- if (pthread_mutex_lock(&key->once.mutex) != 0)
- return error;
- if (volkey->once.state == PTHREAD_NEEDS_INIT) {
- if (key->cleanfn == NULL)
- cleanfn = free;
- else
- cleanfn = key->cleanfn;
- if (pthread_key_create(&key->key, cleanfn) != 0) {
- pthread_mutex_unlock(&key->once.mutex);
- return error;
- }
- key->once.state = PTHREAD_DONE_INIT;
- }
- pthread_mutex_unlock(&key->once.mutex);
- }
-
- /* XXX signals may cause re-entrancy here? */
-
- /* Acquire this key's thread-specific storage: */
- result = pthread_getspecific(key->key);
-
- /* Allocate and initialise storage if unallocated: */
- if (result == NULL) {
- result = malloc(initsz);
- if (result == NULL)
- return error;
- if (pthread_setspecific(key->key, result) != 0) {
- free(result);
- return error;
- }
- memcpy(result, init, initsz);
- }
-
- return result;
-}
diff --git a/lib/libpthread/thread/thread_tag.c b/lib/libpthread/thread/thread_tag.c
new file mode 100644
index 00000000000..43bd4c14b0e
--- /dev/null
+++ b/lib/libpthread/thread/thread_tag.c
@@ -0,0 +1,120 @@
+/* $OpenBSD: thread_tag.c,v 1.1 2004/06/07 21:11:23 marc Exp $ */
+
+/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
+
+#include <sys/time.h>
+
+#include <stdlib.h>
+
+#include "thread_private.h"
+#include "pthread.h"
+#include "pthread_private.h"
+
+/*
+ * A thread tag is a pointer to a structure of this time. An opaque
+ * tag is used to decouple libc from the thread library.
+ */
+struct _thread_tag {
+ pthread_mutex_t m; /* the tag's mutex */
+ pthread_key_t k; /* a key for private data */
+};
+
+/*
+ * local mutex to protect against tag creation races.
+ */
+static pthread_mutex_t _thread_tag_mutex = PTHREAD_MUTEX_INITIALIZER;
+
+/*
+ * Initialize a thread tag structure once. This function is called
+ * if the tag is null. Allocation and initialization are controlled
+ * by a mutex. If the tag is not null when the mutex is obtained
+ * the caller lost a race -- some other thread initialized the tag.
+ * This function will never return NULL.
+ */
+static void
+_thread_tag_init(void **tag)
+{
+ struct _thread_tag *tt;
+ int result;
+
+ result = pthread_mutex_lock(&_thread_tag_mutex);
+ if (result == 0) {
+ if (*tag == NULL) {
+ tt = malloc(sizeof *tt);
+ if (tt != NULL) {
+ result = pthread_mutex_init(&tt->m, NULL);
+ result |= pthread_key_create(&tt->k, free);
+ *tag = tt;
+ }
+ }
+ result |= pthread_mutex_unlock(&_thread_tag_mutex);
+ }
+ if (result != 0)
+ PANIC(__func__);
+}
+
+/*
+ * lock the mutex associated with the given tag
+ */
+void
+_thread_tag_lock(void **tag)
+{
+ struct _thread_tag *tt;
+
+ if (__isthreaded) {
+ if (*tag == NULL)
+ _thread_tag_init(tag);
+ tt = *tag;
+ if (pthread_mutex_lock(&tt->m) != 0)
+ PANIC(__func__);
+ }
+}
+
+/*
+ * unlock the mutex associated with the given tag
+ */
+void
+_thread_tag_unlock(void **tag)
+{
+ struct _thread_tag *tt;
+
+ if (__isthreaded) {
+ if (*tag == NULL)
+ _thread_tag_init(tag);
+ tt = *tag;
+ if (pthread_mutex_unlock(&tt->m) != 0)
+ PANIC(__func__);
+ }
+}
+
+/*
+ * return the thread specific data for the given tag. If there
+ * is no date for this thread initialize it from 'storage'.
+ * On any error return 'err'.
+ */
+void *
+_thread_tag_storage(void **tag, void *storage, size_t sz, void *err)
+{
+ struct _thread_tag *tt;
+ void *ret;
+
+ if (*tag == NULL)
+ _thread_tag_init(tag);
+ tt = *tag;
+
+ ret = pthread_getspecific(tt->k);
+ if (ret == NULL) {
+ ret = malloc(sz);
+ if (ret == NULL)
+ ret = err;
+ else {
+ if (pthread_setspecific(tt->k, ret) == 0)
+ memcpy(ret, storage, sz);
+ else {
+ free(ret);
+ ret = err;
+ }
+ }
+ }
+ return ret;
+}
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h
index afafee5e642..aef55382c95 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.52 2004/02/01 06:22:14 brad Exp $ */
+/* $OpenBSD: pthread_private.h,v 1.53 2004/06/07 21:11:23 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -1117,7 +1117,7 @@ int _thread_fd_table_init(int);
int _thread_fd_table_dup(int, int);
void _thread_fd_table_remove(int);
void _thread_fd_unlock_owned(pthread_t);
-void _thread_fd_unlock_thread(struct pthread *, int, int, const char *, int);
+void _thread_fd_unlock_thread(struct pthread *, int, int);
pthread_addr_t _thread_gc(pthread_addr_t);
void _thread_enter_cancellation_point(void);
void _thread_leave_cancellation_point(void);
diff --git a/lib/libpthread/uthread/uthread_fd.c b/lib/libpthread/uthread/uthread_fd.c
index ac81f56e1f1..a32a09c07e9 100644
--- a/lib/libpthread/uthread/uthread_fd.c
+++ b/lib/libpthread/uthread/uthread_fd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_fd.c,v 1.21 2003/02/14 03:58:42 marc Exp $ */
+/* $OpenBSD: uthread_fd.c,v 1.22 2004/06/07 21:11:23 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -275,8 +275,7 @@ _thread_fd_table_remove(int fd)
* Unlock the fd table entry for a given thread, fd, and lock type.
*/
void
-_thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type,
- const char *fname, int lineno)
+_thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type)
{
struct fd_table_entry *entry;
int ret;
@@ -300,10 +299,7 @@ _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type,
* other threads for clashing with the current
* thread's accesses:
*/
- if (fname)
- _spinlock_debug(&entry->lock, (char *)fname, lineno);
- else
- _SPINLOCK(&entry->lock);
+ _SPINLOCK(&entry->lock);
/* Check if the running thread owns the read lock: */
if (entry->r_owner == thread &&
@@ -393,14 +389,13 @@ _thread_fd_unlock_thread(struct pthread *thread, int fd, int lock_type,
}
/*
- * Unlock an fd table entry for the given fd and lock type. Save
- * fname and lineno (debug variables).
+ * Unlock an fd table entry for the given fd and lock type.
*/
void
-_thread_fd_unlock(int fd, int lock_type, const char *fname, int lineno)
+_thread_fd_unlock(int fd, int lock_type)
{
struct pthread *curthread = _get_curthread();
- _thread_fd_unlock_thread(curthread, fd, lock_type, fname, lineno);
+ _thread_fd_unlock_thread(curthread, fd, lock_type);
}
/*
@@ -429,20 +424,16 @@ _thread_fd_unlock_owned(pthread_t pthread)
}
_SPINUNLOCK(&entry->lock);
if (do_unlock)
- _thread_fd_unlock_thread(pthread, fd, FD_RDWR,
- __FILE__, __LINE__);
+ _thread_fd_unlock_thread(pthread, fd, FD_RDWR);
}
}
}
/*
- * Lock an fd table entry for the given fd and lock type. Save
- * fname and lineno (debug variables). The debug variables may be
- * null when called by the non-debug version of the function.
+ * Lock an fd table entry for the given fd and lock type.
*/
int
-_thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
- const char *fname, int lineno)
+_thread_fd_lock(int fd, int lock_type, struct timespec * timeout)
{
struct pthread *curthread = _get_curthread();
struct fd_table_entry *entry;
@@ -461,11 +452,7 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* other threads for clashing with the current
* thread's accesses:
*/
- if (fname)
- _spinlock_debug(&entry->lock, (char *)fname, lineno);
- else
- _SPINLOCK(&entry->lock);
-
+ _SPINLOCK(&entry->lock);
/* Handle read locks */
if (lock_type == FD_READ || lock_type == FD_RDWR) {
/*
@@ -493,9 +480,6 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* running thread:
*/
curthread->data.fd.fd = fd;
- curthread->data.fd.branch = lineno;
- curthread->data.fd.fname =
- (char *)fname;
/* Set the timeout: */
_thread_kern_set_timeout(timeout);
@@ -536,8 +520,6 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* this file descriptor:
*/
entry->r_lockcount = 0;
- entry->r_fname = fname;
- entry->r_lineno = lineno;
}
}
@@ -573,9 +555,6 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* running thread:
*/
curthread->data.fd.fd = fd;
- curthread->data.fd.branch = lineno;
- curthread->data.fd.fname =
- (char *)fname;
/* Set the timeout: */
_thread_kern_set_timeout(timeout);
@@ -615,8 +594,6 @@ _thread_fd_lock(int fd, int lock_type, struct timespec * timeout,
* for this file descriptor:
*/
entry->w_lockcount = 0;
- entry->w_fname = fname;
- entry->w_lineno = lineno;
}
}
diff --git a/lib/libpthread/uthread/uthread_file.c b/lib/libpthread/uthread/uthread_file.c
index b50174c0d2b..71c0ffc35aa 100644
--- a/lib/libpthread/uthread/uthread_file.c
+++ b/lib/libpthread/uthread/uthread_file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_file.c,v 1.10 2003/01/31 04:46:17 marc Exp $ */
+/* $OpenBSD: uthread_file.c,v 1.11 2004/06/07 21:11:23 marc Exp $ */
/*
* Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -173,7 +173,7 @@ do_lock(int idx, FILE *fp)
}
void
-_flockfile_debug(FILE * fp, char *fname, int lineno)
+flockfile(FILE * fp)
{
int idx = file_idx(fp);
struct file_lock *p;
@@ -230,19 +230,12 @@ _flockfile_debug(FILE * fp, char *fname, int lineno)
_SPINUNLOCK(&hash_lock);
/* Wait on the FILE lock: */
- _thread_kern_sched_state(PS_FILE_WAIT, fname, lineno);
+ _thread_kern_sched_state(PS_FILE_WAIT, "", 0);
}
}
return;
}
-void
-flockfile(FILE * fp)
-{
- _flockfile_debug(fp, (char *) "?", 1);
- return;
-}
-
int
ftrylockfile(FILE * fp)
{
diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c
index 6a1833039e2..531753880e6 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.31 2004/01/15 22:22:12 marc Exp $ */
+/* $OpenBSD: uthread_init.c,v 1.32 2004/06/07 21:11:23 marc Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -134,11 +134,10 @@ static void *references[] = {
&_thread_malloc_init,
&_thread_malloc_lock,
&_thread_malloc_unlock,
- &_libc_private_storage,
- &_libc_private_storage_lock,
- &_libc_private_storage_unlock,
+ &_thread_tag_lock,
+ &_thread_tag_unlock,
+ &_thread_tag_storage,
&flockfile,
- &_flockfile_debug,
&ftrylockfile,
&funlockfile
};