diff options
author | davidxu <davidxu@FreeBSD.org> | 2003-09-06 00:07:52 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2003-09-06 00:07:52 +0000 |
commit | 521fd6195a00e72208369f5622ff85e2d1cf0d88 (patch) | |
tree | 73b871e47699807928698f9459249ea662fc20db /lib | |
parent | 546fd338df0b9b22bd11afd07c5e3e8735c09ab6 (diff) | |
download | FreeBSD-src-521fd6195a00e72208369f5622ff85e2d1cf0d88.zip FreeBSD-src-521fd6195a00e72208369f5622ff85e2d1cf0d88.tar.gz |
Add small piece of code to support pthread_rwlock_timedrdlock and
pthread_rwlock_timedrwlock.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libkse/thread/thr_rwlock.c | 51 | ||||
-rw-r--r-- | lib/libpthread/pthread.map | 4 | ||||
-rw-r--r-- | lib/libpthread/thread/thr_rwlock.c | 51 |
3 files changed, 90 insertions, 16 deletions
diff --git a/lib/libkse/thread/thr_rwlock.c b/lib/libkse/thread/thr_rwlock.c index f9559ab..e1726e5 100644 --- a/lib/libkse/thread/thr_rwlock.c +++ b/lib/libkse/thread/thr_rwlock.c @@ -41,10 +41,12 @@ __weak_reference(_pthread_rwlock_destroy, pthread_rwlock_destroy); __weak_reference(_pthread_rwlock_init, pthread_rwlock_init); __weak_reference(_pthread_rwlock_rdlock, pthread_rwlock_rdlock); +__weak_reference(_pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock); __weak_reference(_pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock); __weak_reference(_pthread_rwlock_trywrlock, pthread_rwlock_trywrlock); __weak_reference(_pthread_rwlock_unlock, pthread_rwlock_unlock); __weak_reference(_pthread_rwlock_wrlock, pthread_rwlock_wrlock); +__weak_reference(_pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock); /* * Prototypes @@ -137,8 +139,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; int ret; @@ -162,8 +164,12 @@ _pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) /* give writers priority over readers */ while (prwlock->blocked_writers || prwlock->state < 0) { - ret = _thr_cond_wait(&prwlock->read_signal, &prwlock->lock); - + if (abstime) + ret = _pthread_cond_timedwait(&prwlock->read_signal, + &prwlock->lock, abstime); + else + ret = _thr_cond_wait(&prwlock->read_signal, + &prwlock->lock); if (ret != 0) { /* can't do a whole lot if this fails */ _thr_mutex_unlock(&prwlock->lock); @@ -188,9 +194,22 @@ _pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) return (ret); } +int +_pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) +{ + return rwlock_rdlock_common (rwlock, NULL); +} + __strong_reference(_pthread_rwlock_rdlock, _thr_rwlock_rdlock); 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; @@ -301,8 +320,8 @@ _pthread_rwlock_unlock (pthread_rwlock_t *rwlock) __strong_reference(_pthread_rwlock_unlock, _thr_rwlock_unlock); -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; @@ -327,8 +346,12 @@ _pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) while (prwlock->state != 0) { ++prwlock->blocked_writers; - ret = _thr_cond_wait(&prwlock->write_signal, &prwlock->lock); - + if (abstime != NULL) + ret = _pthread_cond_timedwait(&prwlock->write_signal, + &prwlock->lock, abstime); + else + ret = _thr_cond_wait(&prwlock->write_signal, + &prwlock->lock); if (ret != 0) { --prwlock->blocked_writers; _thr_mutex_unlock(&prwlock->lock); @@ -347,4 +370,16 @@ _pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) return (ret); } +int +_pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) +{ + return rwlock_wrlock_common (rwlock, NULL); +} __strong_reference(_pthread_rwlock_wrlock, _thr_rwlock_wrlock); + +int +_pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, + const struct timespec *abstime) +{ + return rwlock_wrlock_common (rwlock, abstime); +} diff --git a/lib/libpthread/pthread.map b/lib/libpthread/pthread.map index 62f4635..c424218 100644 --- a/lib/libpthread/pthread.map +++ b/lib/libpthread/pthread.map @@ -108,6 +108,8 @@ global: _pthread_rwlock_destroy; _pthread_rwlock_init; _pthread_rwlock_rdlock; + _pthread_rwlock_timedrdlock; + _pthread_rwlock_timedwrlock; _pthread_rwlock_tryrdlock; _pthread_rwlock_trywrlock; _pthread_rwlock_unlock; @@ -249,6 +251,8 @@ global: pthread_rwlock_destroy; pthread_rwlock_init; pthread_rwlock_rdlock; + pthread_rwlock_timedrdlock; + pthread_rwlock_timedwrlock; pthread_rwlock_tryrdlock; pthread_rwlock_trywrlock; pthread_rwlock_unlock; diff --git a/lib/libpthread/thread/thr_rwlock.c b/lib/libpthread/thread/thr_rwlock.c index f9559ab..e1726e5 100644 --- a/lib/libpthread/thread/thr_rwlock.c +++ b/lib/libpthread/thread/thr_rwlock.c @@ -41,10 +41,12 @@ __weak_reference(_pthread_rwlock_destroy, pthread_rwlock_destroy); __weak_reference(_pthread_rwlock_init, pthread_rwlock_init); __weak_reference(_pthread_rwlock_rdlock, pthread_rwlock_rdlock); +__weak_reference(_pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock); __weak_reference(_pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock); __weak_reference(_pthread_rwlock_trywrlock, pthread_rwlock_trywrlock); __weak_reference(_pthread_rwlock_unlock, pthread_rwlock_unlock); __weak_reference(_pthread_rwlock_wrlock, pthread_rwlock_wrlock); +__weak_reference(_pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock); /* * Prototypes @@ -137,8 +139,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; int ret; @@ -162,8 +164,12 @@ _pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) /* give writers priority over readers */ while (prwlock->blocked_writers || prwlock->state < 0) { - ret = _thr_cond_wait(&prwlock->read_signal, &prwlock->lock); - + if (abstime) + ret = _pthread_cond_timedwait(&prwlock->read_signal, + &prwlock->lock, abstime); + else + ret = _thr_cond_wait(&prwlock->read_signal, + &prwlock->lock); if (ret != 0) { /* can't do a whole lot if this fails */ _thr_mutex_unlock(&prwlock->lock); @@ -188,9 +194,22 @@ _pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) return (ret); } +int +_pthread_rwlock_rdlock (pthread_rwlock_t *rwlock) +{ + return rwlock_rdlock_common (rwlock, NULL); +} + __strong_reference(_pthread_rwlock_rdlock, _thr_rwlock_rdlock); 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; @@ -301,8 +320,8 @@ _pthread_rwlock_unlock (pthread_rwlock_t *rwlock) __strong_reference(_pthread_rwlock_unlock, _thr_rwlock_unlock); -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; @@ -327,8 +346,12 @@ _pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) while (prwlock->state != 0) { ++prwlock->blocked_writers; - ret = _thr_cond_wait(&prwlock->write_signal, &prwlock->lock); - + if (abstime != NULL) + ret = _pthread_cond_timedwait(&prwlock->write_signal, + &prwlock->lock, abstime); + else + ret = _thr_cond_wait(&prwlock->write_signal, + &prwlock->lock); if (ret != 0) { --prwlock->blocked_writers; _thr_mutex_unlock(&prwlock->lock); @@ -347,4 +370,16 @@ _pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) return (ret); } +int +_pthread_rwlock_wrlock (pthread_rwlock_t *rwlock) +{ + return rwlock_wrlock_common (rwlock, NULL); +} __strong_reference(_pthread_rwlock_wrlock, _thr_rwlock_wrlock); + +int +_pthread_rwlock_timedwrlock (pthread_rwlock_t *rwlock, + const struct timespec *abstime) +{ + return rwlock_wrlock_common (rwlock, abstime); +} |