summaryrefslogtreecommitdiff
path: root/lib/librthread
diff options
context:
space:
mode:
authorMarco S Hyman <marc@cvs.openbsd.org>2006-01-05 04:06:49 +0000
committerMarco S Hyman <marc@cvs.openbsd.org>2006-01-05 04:06:49 +0000
commita1d0ddad6a3714e2f9848d55f7bf68bfc73087b6 (patch)
tree2bd741fc5dd562800ac0ccfc38fc52ac138b89b1 /lib/librthread
parent4f2f633593bcff3fc73430c2375dff9f1eafb9fa (diff)
add -Wstrict-prototypes -Wmissing-prototypes -Wsign-compare
Minor tweaks to compile with the above, primarily in fixing the conflicts between semaphore.h and rthread.h "i like the additional warnings" tedu@
Diffstat (limited to 'lib/librthread')
-rw-r--r--lib/librthread/Makefile8
-rw-r--r--lib/librthread/rthread.c9
-rw-r--r--lib/librthread/rthread.h16
-rw-r--r--lib/librthread/rthread_attr.c9
-rw-r--r--lib/librthread/rthread_libc.c127
-rw-r--r--lib/librthread/rthread_sync.c4
6 files changed, 157 insertions, 16 deletions
diff --git a/lib/librthread/Makefile b/lib/librthread/Makefile
index e8438e2823c..1b325c8b8fb 100644
--- a/lib/librthread/Makefile
+++ b/lib/librthread/Makefile
@@ -1,14 +1,18 @@
-# $OpenBSD: Makefile,v 1.8 2006/01/04 19:48:52 otto Exp $
+# $OpenBSD: Makefile,v 1.9 2006/01/05 04:06:48 marc Exp $
LIB=rthread
WANTLINT=
LINTFLAGS=-z
+LIBCSRCDIR= ${.CURDIR}/../libc
+
CFLAGS+=-Wall -g -Werror -Wshadow
+CFLAGS+=-Wstrict-prototypes -Wmissing-prototypes -Wsign-compare
+CFLAGS+=-I${LIBCSRCDIR}/include
.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}
SRCS= rthread.c rthread_attr.c rthread_sched.c rthread_sync.c rthread_tls.c \
rthread_sig.c rthread_np.c rthread_debug.c rthread_stack.c \
- rthread_reaper.c
+ rthread_reaper.c rthread_libc.c
OBJS+= _atomic_lock.o rfork_thread.o
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c
index 975a35845ef..452ad6ce3c3 100644
--- a/lib/librthread/rthread.c
+++ b/lib/librthread/rthread.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread.c,v 1.28 2006/01/04 19:48:52 otto Exp $ */
+/* $OpenBSD: rthread.c,v 1.29 2006/01/05 04:06:48 marc Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -37,6 +37,7 @@
#include <pthread.h>
+#include "thread_private.h" /* in libc/include */
#include "rthread.h"
static int concurrency_level; /* not used */
@@ -452,18 +453,18 @@ _thread_dump_info(void)
static _spinlock_lock_t malloc_lock = _SPINLOCK_UNLOCKED;
void
-_thread_malloc_lock()
+_thread_malloc_lock(void)
{
_spinlock(&malloc_lock);
}
void
-_thread_malloc_unlock()
+_thread_malloc_unlock(void)
{
_spinunlock(&malloc_lock);
}
void
-_thread_malloc_init()
+_thread_malloc_init(void)
{
}
diff --git a/lib/librthread/rthread.h b/lib/librthread/rthread.h
index 04b8d04e8a9..918a00d9e1c 100644
--- a/lib/librthread/rthread.h
+++ b/lib/librthread/rthread.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread.h,v 1.16 2006/01/04 19:48:52 otto Exp $ */
+/* $OpenBSD: rthread.h,v 1.17 2006/01/05 04:06:48 marc Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -26,6 +26,7 @@
*/
#include <sys/queue.h>
+#include <semaphore.h>
#define RTHREAD_STACK_SIZE_DEF (64 * 1024)
@@ -37,15 +38,15 @@ struct stack {
size_t len;
};
-typedef struct semaphore {
+struct sem {
_spinlock_lock_t lock;
volatile int waitcount;
volatile int value;
int pad;
-} *sem_t;
+};
struct pthread_mutex {
- struct semaphore sem;
+ struct sem sem;
int type;
pthread_t owner;
int count;
@@ -56,7 +57,7 @@ struct pthread_mutex_attr {
};
struct pthread_cond {
- struct semaphore sem;
+ struct sem sem;
};
struct pthread_cond_attr {
@@ -64,7 +65,7 @@ struct pthread_cond_attr {
};
struct pthread_rwlock {
- struct semaphore sem;
+ struct sem sem;
_spinlock_lock_t lock;
int readers;
int writer;
@@ -104,7 +105,7 @@ struct rthread_cleanup_fn {
};
struct pthread {
- struct semaphore donesem;
+ struct sem donesem;
pid_t tid;
unsigned int flags;
_spinlock_lock_t flags_lock;
@@ -146,6 +147,7 @@ void _rthread_free_stack(struct stack *);
void _rthread_tls_destructors(pthread_t);
void _rthread_debug(int, const char *, ...)
__attribute__((__format__ (printf, 2, 3)));
+void _rthread_debug_init(void);
void _rthread_add_to_reaper(pid_t, struct stack *);
void _rthread_reaper(void);
diff --git a/lib/librthread/rthread_attr.c b/lib/librthread/rthread_attr.c
index 8b50aca3e7a..4806aef0eb2 100644
--- a/lib/librthread/rthread_attr.c
+++ b/lib/librthread/rthread_attr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_attr.c,v 1.6 2006/01/04 08:48:02 marc Exp $ */
+/* $OpenBSD: rthread_attr.c,v 1.7 2006/01/05 04:06:48 marc Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -33,10 +33,17 @@
#include <errno.h>
#include <pthread.h>
+#include <pthread_np.h>
#include "rthread.h"
/*
+ * temp: these need to be added to pthread.h
+ */
+int pthread_attr_getguardsize(const pthread_attr_t *, size_t *);
+int pthread_attr_setguardsize(pthread_attr_t *, size_t);
+
+/*
* Note: stack_size + guard_size == total stack used
*
* pthread_attr_init MUST be called before any other attribute function
diff --git a/lib/librthread/rthread_libc.c b/lib/librthread/rthread_libc.c
new file mode 100644
index 00000000000..d50a1e09d08
--- /dev/null
+++ b/lib/librthread/rthread_libc.c
@@ -0,0 +1,127 @@
+/* $OpenBSD: rthread_libc.c,v 1.1 2006/01/05 04:06:48 marc Exp $ */
+/* $snafu: libc_tag.c,v 1.4 2004/11/30 07:00:06 marc Exp $ */
+
+/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
+
+#define _POSIX_THREADS
+
+#include <sys/time.h>
+
+#include <machine/spinlock.h>
+
+#include <pthread.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "thread_private.h" /* in libc/include */
+
+#include "rthread.h"
+
+/*
+ * A thread tag is a pointer to a structure of this type. 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)
+ _rthread_debug(1, "tag init failure");
+}
+
+/*
+ * 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)
+ _rthread_debug(1, "tag mutex lock failure");
+ }
+}
+
+/*
+ * 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)
+ _rthread_debug(1, "tag mutex unlock failure");
+ }
+}
+
+/*
+ * 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/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c
index 5f1f8a6c388..47d8ccda1fa 100644
--- a/lib/librthread/rthread_sync.c
+++ b/lib/librthread/rthread_sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_sync.c,v 1.15 2005/12/31 20:07:41 brad Exp $ */
+/* $OpenBSD: rthread_sync.c,v 1.16 2006/01/05 04:06:48 marc Exp $ */
/*
* Copyright (c) 2004,2005 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -249,7 +249,7 @@ pthread_mutex_destroy(pthread_mutex_t *mutexp)
return (0);
}
-int
+static int
_rthread_mutex_lock(pthread_mutex_t *mutexp, int trywait)
{
pthread_mutex_t mutex = *mutexp;