summaryrefslogtreecommitdiff
path: root/lib/librthread
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2005-12-07 03:18:40 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2005-12-07 03:18:40 +0000
commite0476a9099bc24bd297b143f08d405d98383bd47 (patch)
tree04d7b6e8767142c05aacea2ec8720afef823b5dc /lib/librthread
parent96111fb473a4c9d232acf18785b490aa73a1fcf1 (diff)
add the posix semaphore functions. this lets vlc work.
ok brad
Diffstat (limited to 'lib/librthread')
-rw-r--r--lib/librthread/Makefile4
-rw-r--r--lib/librthread/rthread_sync.c94
2 files changed, 91 insertions, 7 deletions
diff --git a/lib/librthread/Makefile b/lib/librthread/Makefile
index 62c7cbcbfb7..b61663c6290 100644
--- a/lib/librthread/Makefile
+++ b/lib/librthread/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.2 2005/12/03 18:36:40 tedu Exp $
+# $OpenBSD: Makefile,v 1.3 2005/12/07 03:18:39 tedu Exp $
LIB=rthread
-CFLAGS+=-Wall -g -Werror
+CFLAGS+=-Wall -g -Werror -Wshadow
.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}
SRCS= rthread.c rthread_attr.c rthread_sched.c rthread_sync.c rthread_tls.c rthread_sig.c
diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c
index 262983a926d..12361e612ad 100644
--- a/lib/librthread/rthread_sync.c
+++ b/lib/librthread/rthread_sync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_sync.c,v 1.2 2005/12/06 06:19:31 tedu Exp $ */
+/* $OpenBSD: rthread_sync.c,v 1.3 2005/12/07 03:18:39 tedu Exp $ */
/*
* Copyright (c) 2004 Ted Unangst <tedu@openbsd.org>
* All Rights Reserved.
@@ -46,7 +46,7 @@ int thrwakeup(long);
int
_sem_wait(sem_t sem, int tryonly, int timo)
{
- int sleep;
+ int do_sleep;
_spinlock(&sem->lock);
again:
@@ -56,13 +56,13 @@ again:
return (0);
}
sem->waitcount++;
- sleep = 1;
+ do_sleep = 1;
} else {
sem->value--;
- sleep = 0;
+ do_sleep = 0;
}
- if (sleep) {
+ if (do_sleep) {
if (thrsleep((long)sem, timo, &sem->lock) == EWOULDBLOCK)
return (0);
_spinlock(&sem->lock);
@@ -103,6 +103,87 @@ _sem_wakeall(sem_t sem)
}
/*
+ * exported semaphores
+ */
+int
+sem_init(sem_t *semp, int pshared, unsigned int value)
+{
+ sem_t sem;
+
+ if (pshared) {
+ errno = EPERM;
+ return (-1);
+ }
+
+ sem = malloc(sizeof(*sem));
+ if (!sem)
+ return (-1);
+ memset(sem, 0, sizeof(*sem));
+ sem->value = value;
+ *semp = sem;
+
+ return (0);
+}
+
+int
+sem_destroy(sem_t *semp)
+{
+ /* should check for waiters */
+ free(*semp);
+ *semp = NULL;
+
+ return (0);
+}
+
+int
+sem_getvalue(sem_t *semp, int *sval)
+{
+ sem_t sem = *semp;
+
+ _spinlock(&sem->lock);
+ *sval = sem->value;
+ _spinunlock(&sem->lock);
+
+ return (0);
+}
+
+int
+sem_post(sem_t *semp)
+{
+ sem_t sem = *semp;
+
+ _sem_wakeup(sem);
+
+ return (0);
+}
+
+int
+sem_wait(sem_t *semp)
+{
+ sem_t sem = *semp;
+
+ _sem_wait(sem, 0, 0);
+
+ return (0);
+}
+
+int
+sem_trywait(sem_t *semp)
+{
+ sem_t sem = *semp;
+ int rv;
+
+ rv = _sem_wait(sem, 1, 0);
+
+ if (!rv) {
+ errno = EAGAIN;
+ return (-1);
+ }
+
+ return (0);
+}
+
+/*
* mutexen
*/
int
@@ -476,6 +557,9 @@ pthread_rwlockattr_destory(pthread_rwlockattr_t *attrp)
return (0);
}
+/*
+ * pthread_once
+ */
int
pthread_once(pthread_once_t *once_control, void (*init_routine)(void))
{