Add small piece of code to support pthread_rwlock_timedrdlock and

pthread_rwlock_timedrwlock.
This commit is contained in:
davidxu 2003-09-06 00:07:52 +00:00
parent 546fd338df
commit 521fd6195a
4 changed files with 94 additions and 16 deletions

View File

@ -258,6 +258,10 @@ int pthread_rwlock_destroy(pthread_rwlock_t *);
int pthread_rwlock_init(pthread_rwlock_t *,
const pthread_rwlockattr_t *);
int pthread_rwlock_rdlock(pthread_rwlock_t *);
int pthread_rwlock_timedrdlock(pthread_rwlock_t *,
const struct timespec *);
int pthread_rwlock_timedrwlock(pthread_rwlock_t *,
const struct timespec *);
int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
int pthread_rwlock_trywrlock(pthread_rwlock_t *);
int pthread_rwlock_unlock(pthread_rwlock_t *);

View File

@ -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,8 +194,21 @@ _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)
{
@ -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);
}

View File

@ -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;

View File

@ -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,8 +194,21 @@ _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)
{
@ -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);
}