diff options
-rw-r--r-- | lib/librthread/rthread.c | 6 | ||||
-rw-r--r-- | lib/librthread/rthread.h | 3 | ||||
-rw-r--r-- | lib/librthread/rthread_sync.c | 27 |
3 files changed, 27 insertions, 9 deletions
diff --git a/lib/librthread/rthread.c b/lib/librthread/rthread.c index 46b4e4f7634..e60ef5f51a1 100644 --- a/lib/librthread/rthread.c +++ b/lib/librthread/rthread.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.c,v 1.2 2005/12/03 18:17:55 tedu Exp $ */ +/* $OpenBSD: rthread.c,v 1.3 2005/12/13 05:56:55 tedu Exp $ */ /* * Copyright (c) 2004 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -143,7 +143,7 @@ pthread_exit(void *retval) thread->retval = retval; thread->flags |= THREAD_DONE; - _sem_wakeup(&thread->donesem); + _sem_post(&thread->donesem); #if 0 if (thread->flags & THREAD_DETACHED) free(thread); @@ -157,7 +157,6 @@ pthread_join(pthread_t thread, void **retval) { _sem_wait(&thread->donesem, 0, 0); - printf("joined %d %p\n", thread->tid, thread->retval); if (retval) *retval = thread->retval; @@ -203,7 +202,6 @@ pthread_create(pthread_t *threadp, const pthread_attr_t *attr, thread->stack->sp, thread_start, thread); /* new thread will appear thread_start */ thread->tid = tid; - printf("new thread %d\n", tid); *threadp = thread; _spinunlock(&thread_lock); diff --git a/lib/librthread/rthread.h b/lib/librthread/rthread.h index 3deec5835d5..be9c6f93307 100644 --- a/lib/librthread/rthread.h +++ b/lib/librthread/rthread.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread.h,v 1.1 2005/12/03 18:16:19 tedu Exp $ */ +/* $OpenBSD: rthread.h,v 1.2 2005/12/13 05:56:55 tedu Exp $ */ /* * Copyright (c) 2004 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -105,6 +105,7 @@ struct pthread { void _spinlock(_spinlock_lock_t *); void _spinunlock(_spinlock_lock_t *); int _sem_wait(sem_t, int, int); +int _sem_post(sem_t); int _sem_wakeup(sem_t); int _sem_wakeall(sem_t); diff --git a/lib/librthread/rthread_sync.c b/lib/librthread/rthread_sync.c index 12361e612ad..3cc11a8a8ec 100644 --- a/lib/librthread/rthread_sync.c +++ b/lib/librthread/rthread_sync.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rthread_sync.c,v 1.3 2005/12/07 03:18:39 tedu Exp $ */ +/* $OpenBSD: rthread_sync.c,v 1.4 2005/12/13 05:56:55 tedu Exp $ */ /* * Copyright (c) 2004 Ted Unangst <tedu@openbsd.org> * All Rights Reserved. @@ -37,6 +37,7 @@ #include "rthread.h" + int thrsleep(long, int, void *); int thrwakeup(long); @@ -73,8 +74,9 @@ again: return (1); } +/* always increment count */ int -_sem_wakeup(sem_t sem) +_sem_post(sem_t sem) { int rv = 0; @@ -88,6 +90,23 @@ _sem_wakeup(sem_t sem) return (rv); } +/* only increment count if a waiter */ +int +_sem_wakeup(sem_t sem) +{ + int rv = 0; + + _spinlock(&sem->lock); + if (sem->waitcount) { + sem->value++; + thrwakeup((long)sem); + rv = 1; + } + _spinunlock(&sem->lock); + return (rv); +} + + int _sem_wakeall(sem_t sem) { @@ -152,7 +171,7 @@ sem_post(sem_t *semp) { sem_t sem = *semp; - _sem_wakeup(sem); + _sem_post(sem); return (0); } @@ -261,7 +280,7 @@ pthread_mutex_unlock(pthread_mutex_t *mutexp) if (--mutex->count == 0) { mutex->owner = NULL; - _sem_wakeup((void *)&mutex->sem); + _sem_post((void *)&mutex->sem); } return (0); |