diff options
author | davidxu <davidxu@FreeBSD.org> | 2012-02-27 13:38:52 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2012-02-27 13:38:52 +0000 |
commit | 96aacc2279b7b65fc0c8ff707abe3d020c1e8378 (patch) | |
tree | 9e46c0856016e3264151a062bf52ebb933fca926 /lib/libthr | |
parent | 8a35bc6c4fda7b720a969d6cb7122d1667a826d5 (diff) | |
download | FreeBSD-src-96aacc2279b7b65fc0c8ff707abe3d020c1e8378.zip FreeBSD-src-96aacc2279b7b65fc0c8ff707abe3d020c1e8378.tar.gz |
Follow changes made in revision 232144, pass absolute timeout to kernel,
this eliminates a clock_gettime() syscall.
Diffstat (limited to 'lib/libthr')
-rw-r--r-- | lib/libthr/thread/thr_rwlock.c | 26 | ||||
-rw-r--r-- | lib/libthr/thread/thr_umtx.c | 35 | ||||
-rw-r--r-- | lib/libthr/thread/thr_umtx.h | 6 |
3 files changed, 37 insertions, 30 deletions
diff --git a/lib/libthr/thread/thr_rwlock.c b/lib/libthr/thread/thr_rwlock.c index ebdeae7..397663e 100644 --- a/lib/libthr/thread/thr_rwlock.c +++ b/lib/libthr/thread/thr_rwlock.c @@ -123,7 +123,6 @@ rwlock_rdlock_common(pthread_rwlock_t *rwlock, const struct timespec *abstime) { struct pthread *curthread = _get_curthread(); pthread_rwlock_t prwlock; - struct timespec ts, ts2, *tsp; int flags; int ret; @@ -162,18 +161,8 @@ rwlock_rdlock_common(pthread_rwlock_t *rwlock, const struct timespec *abstime) return (EINVAL); for (;;) { - if (abstime) { - clock_gettime(CLOCK_REALTIME, &ts); - TIMESPEC_SUB(&ts2, abstime, &ts); - if (ts2.tv_sec < 0 || - (ts2.tv_sec == 0 && ts2.tv_nsec <= 0)) - return (ETIMEDOUT); - tsp = &ts2; - } else - tsp = NULL; - /* goto kernel and lock it */ - ret = __thr_rwlock_rdlock(&prwlock->lock, flags, tsp); + ret = __thr_rwlock_rdlock(&prwlock->lock, flags, abstime); if (ret != EINTR) break; @@ -255,7 +244,6 @@ rwlock_wrlock_common (pthread_rwlock_t *rwlock, const struct timespec *abstime) { struct pthread *curthread = _get_curthread(); pthread_rwlock_t prwlock; - struct timespec ts, ts2, *tsp; int ret; CHECK_AND_INIT_RWLOCK @@ -275,18 +263,8 @@ rwlock_wrlock_common (pthread_rwlock_t *rwlock, const struct timespec *abstime) return (EINVAL); for (;;) { - if (abstime != NULL) { - clock_gettime(CLOCK_REALTIME, &ts); - TIMESPEC_SUB(&ts2, abstime, &ts); - if (ts2.tv_sec < 0 || - (ts2.tv_sec == 0 && ts2.tv_nsec <= 0)) - return (ETIMEDOUT); - tsp = &ts2; - } else - tsp = NULL; - /* goto kernel and lock it */ - ret = __thr_rwlock_wrlock(&prwlock->lock, tsp); + ret = __thr_rwlock_wrlock(&prwlock->lock, abstime); if (ret == 0) { prwlock->owner = curthread; break; diff --git a/lib/libthr/thread/thr_umtx.c b/lib/libthr/thread/thr_umtx.c index 38c3b04..f32596f 100644 --- a/lib/libthr/thread/thr_umtx.c +++ b/lib/libthr/thread/thr_umtx.c @@ -265,15 +265,42 @@ _thr_ucond_broadcast(struct ucond *cv) } int -__thr_rwlock_rdlock(struct urwlock *rwlock, int flags, struct timespec *tsp) +__thr_rwlock_rdlock(struct urwlock *rwlock, int flags, + const struct timespec *tsp) { - return _umtx_op_err(rwlock, UMTX_OP_RW_RDLOCK, flags, NULL, tsp); + struct _umtx_time timeout, *tm_p; + size_t tm_size; + + if (tsp == NULL) { + tm_p = NULL; + tm_size = 0; + } else { + timeout._timeout = *tsp; + timeout._flags = UMTX_ABSTIME; + timeout._clockid = CLOCK_REALTIME; + tm_p = &timeout; + tm_size = sizeof(timeout); + } + return _umtx_op_err(rwlock, UMTX_OP_RW_RDLOCK, flags, (void *)tm_size, tm_p); } int -__thr_rwlock_wrlock(struct urwlock *rwlock, struct timespec *tsp) +__thr_rwlock_wrlock(struct urwlock *rwlock, const struct timespec *tsp) { - return _umtx_op_err(rwlock, UMTX_OP_RW_WRLOCK, 0, NULL, tsp); + struct _umtx_time timeout, *tm_p; + size_t tm_size; + + if (tsp == NULL) { + tm_p = NULL; + tm_size = 0; + } else { + timeout._timeout = *tsp; + timeout._flags = UMTX_ABSTIME; + timeout._clockid = CLOCK_REALTIME; + tm_p = &timeout; + tm_size = sizeof(timeout); + } + return _umtx_op_err(rwlock, UMTX_OP_RW_WRLOCK, 0, (void *)tm_size, tm_p); } int diff --git a/lib/libthr/thread/thr_umtx.h b/lib/libthr/thread/thr_umtx.h index 0a8034b..61a74a8 100644 --- a/lib/libthr/thread/thr_umtx.h +++ b/lib/libthr/thread/thr_umtx.h @@ -60,8 +60,10 @@ void _thr_ucond_init(struct ucond *cv) __hidden; int _thr_ucond_signal(struct ucond *cv) __hidden; int _thr_ucond_broadcast(struct ucond *cv) __hidden; -int __thr_rwlock_rdlock(struct urwlock *rwlock, int flags, struct timespec *tsp) __hidden; -int __thr_rwlock_wrlock(struct urwlock *rwlock, struct timespec *tsp) __hidden; +int __thr_rwlock_rdlock(struct urwlock *rwlock, int flags, + const struct timespec *tsp) __hidden; +int __thr_rwlock_wrlock(struct urwlock *rwlock, + const struct timespec *tsp) __hidden; int __thr_rwlock_unlock(struct urwlock *rwlock) __hidden; /* Internal used only */ |