svn commit: r214815 - user/davidxu/libthr/lib/libthr/thread
David Xu
davidxu at FreeBSD.org
Fri Nov 5 00:25:14 UTC 2010
Author: davidxu
Date: Fri Nov 5 00:25:13 2010
New Revision: 214815
URL: http://svn.freebsd.org/changeset/base/214815
Log:
Move clock_gettime() after lock released. we should have another
UMTX_OP_WAIT with absolute timeout to save syscalls.
Modified:
user/davidxu/libthr/lib/libthr/thread/thr_cond.c
Modified: user/davidxu/libthr/lib/libthr/thread/thr_cond.c
==============================================================================
--- user/davidxu/libthr/lib/libthr/thread/thr_cond.c Fri Nov 5 00:07:56 2010 (r214814)
+++ user/davidxu/libthr/lib/libthr/thread/thr_cond.c Fri Nov 5 00:25:13 2010 (r214815)
@@ -224,18 +224,18 @@ cond_wait_user(pthread_cond_t *cond, pth
return (ret);
}
- if (abstime != NULL) {
- clock_gettime(cv->c_kerncv.c_clockid, &ts);
- TIMESPEC_SUB(&ts2, abstime, &ts);
- tsp = &ts2;
- } else
- tsp = NULL;
-
bseq = cv->c_broadcast_seq;
for(;;) {
seq = cv->c_seq;
THR_UMUTEX_UNLOCK(curthread, &cv->c_lock);
+ if (abstime != NULL) {
+ clock_gettime(cv->c_kerncv.c_clockid, &ts);
+ TIMESPEC_SUB(&ts2, abstime, &ts);
+ tsp = &ts2;
+ } else
+ tsp = NULL;
+
if (cancel) {
_thr_cancel_enter2(curthread, 0);
ret = _thr_umtx_wait_uint((u_int *)&cv->c_seq,
@@ -255,10 +255,12 @@ cond_wait_user(pthread_cond_t *cond, pth
cv->c_signaled--;
ret = 0;
break;
+ } else if (ret == ETIMEDOUT) {
+ break;
} else if (cancel && SHOULD_CANCEL(curthread) &&
!THR_IN_CRITICAL(curthread)) {
- THR_UMUTEX_UNLOCK(curthread, &cv->c_lock);
- _pthread_exit(PTHREAD_CANCELED);
+ THR_UMUTEX_UNLOCK(curthread, &cv->c_lock);
+ _pthread_exit(PTHREAD_CANCELED);
}
}
THR_UMUTEX_UNLOCK(curthread, &cv->c_lock);
@@ -289,6 +291,7 @@ cond_wait_common(pthread_cond_t *cond, p
return (err);
m = *mutex;
+
if ((m->m_lock.m_flags & USYNC_PROCESS_SHARED) !=
(cv->c_kerncv.c_flags & USYNC_PROCESS_SHARED))
return (EINVAL);
More information about the svn-src-user
mailing list