summaryrefslogtreecommitdiff
path: root/lib/libpthread/uthread
diff options
context:
space:
mode:
authorTed Unangst <tedu@cvs.openbsd.org>2010-04-12 01:54:24 +0000
committerTed Unangst <tedu@cvs.openbsd.org>2010-04-12 01:54:24 +0000
commit41c1a3e3e6683fe9b4edf023cd5a862fd79746b0 (patch)
treeefce53ab5ec5de44259e6fae7768cc9358cbce71 /lib/libpthread/uthread
parent46975a2a516f3489a5273d971ef327e5c5fd681e (diff)
Add support for pthread_rwlock_timed locks.
from brad. ok kurt, who's too busy to commit
Diffstat (limited to 'lib/libpthread/uthread')
-rw-r--r--lib/libpthread/uthread/uthread_rwlock.c54
1 files changed, 45 insertions, 9 deletions
diff --git a/lib/libpthread/uthread/uthread_rwlock.c b/lib/libpthread/uthread/uthread_rwlock.c
index b5c2d4da339..cf6edf5e6d7 100644
--- a/lib/libpthread/uthread/uthread_rwlock.c
+++ b/lib/libpthread/uthread/uthread_rwlock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_rwlock.c,v 1.6 2007/05/18 19:28:50 kurt Exp $ */
+/* $OpenBSD: uthread_rwlock.c,v 1.7 2010/04/12 01:54:23 tedu Exp $ */
/*-
* Copyright (c) 1998 Alex Nash
* All rights reserved.
@@ -127,8 +127,8 @@ pthread_rwlock_init (pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
return (ret);
}
-int
-pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
+static int
+rwlock_rdlock_common (pthread_rwlock_t *rwlock, const struct timespec *abstime)
{
pthread_rwlock_t prwlock;
struct pthread *curthread;
@@ -175,8 +175,13 @@ pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
} else {
/* give writers priority over readers */
while (prwlock->blocked_writers || prwlock->state < 0) {
- ret = pthread_cond_wait(&prwlock->read_signal,
- &prwlock->lock);
+ if (abstime) {
+ ret = pthread_cond_timedwait(&prwlock->read_signal,
+ &prwlock->lock, abstime);
+ } else {
+ ret = pthread_cond_wait(&prwlock->read_signal,
+ &prwlock->lock);
+ }
if (ret != 0) {
/* can't do a whole lot if this fails */
@@ -201,6 +206,19 @@ pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
}
int
+pthread_rwlock_rdlock (pthread_rwlock_t *rwlock)
+{
+ return rwlock_rdlock_common (rwlock, NULL);
+}
+
+int
+pthread_rwlock_timedrdlock (pthread_rwlock_t *rwlock,
+ const struct timespec *abstime)
+{
+ return rwlock_rdlock_common(rwlock, abstime);
+}
+
+int
pthread_rwlock_tryrdlock (pthread_rwlock_t *rwlock)
{
pthread_rwlock_t prwlock;
@@ -322,8 +340,8 @@ pthread_rwlock_unlock (pthread_rwlock_t *rwlock)
return (ret);
}
-int
-pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
+static int
+rwlock_wrlock_common (pthread_rwlock_t *rwlock, const struct timespec *abstime)
{
pthread_rwlock_t prwlock;
int ret;
@@ -348,8 +366,13 @@ pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
while (prwlock->state != 0) {
prwlock->blocked_writers++;
- ret = pthread_cond_wait(&prwlock->write_signal,
- &prwlock->lock);
+ if (abstime != NULL) {
+ ret = pthread_cond_timedwait(&prwlock->write_signal,
+ &prwlock->lock, abstime);
+ } else {
+ ret = pthread_cond_wait(&prwlock->write_signal,
+ &prwlock->lock);
+ }
if (ret != 0) {
prwlock->blocked_writers--;
@@ -369,4 +392,17 @@ pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
return (ret);
}
+int
+pthread_rwlock_wrlock (pthread_rwlock_t *rwlock)
+{
+ return rwlock_wrlock_common (rwlock, NULL);
+}
+
+int
+pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock,
+ const struct timespec *abstime)
+{
+ return rwlock_wrlock_common (rwlock, abstime);
+}
+
#endif /* _THREAD_SAFE */