1/* 2 * Copyright (c) 2005 David Xu <davidxu@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/lib/libthr/thread/thr_cond.c 211524 2010-08-20 05:15:39Z davidxu $ |
27 */ 28 29#include "namespace.h" 30#include <stdlib.h> 31#include <errno.h> 32#include <string.h> 33#include <pthread.h> 34#include <limits.h> --- 122 unchanged lines hidden (view full) --- 157 158 if (info->cond != NULL) { 159 cv = *(info->cond); 160 THR_UMUTEX_UNLOCK(curthread, &cv->c_lock); 161 } 162 _mutex_cv_lock(info->mutex, info->count); 163} 164 |
165/* 166 * Cancellation behaivor: 167 * Thread may be canceled at start, if thread is canceled, it means it 168 * did not get a wakeup from pthread_cond_signal(), otherwise, it is 169 * not canceled. 170 * Thread cancellation never cause wakeup from pthread_cond_signal() 171 * to be lost. 172 */ |
173static int 174cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex, 175 const struct timespec *abstime, int cancel) 176{ 177 struct pthread *curthread = _get_curthread(); 178 struct timespec ts, ts2, *tsp; 179 struct cond_cancel_info info; 180 pthread_cond_t cv; 181 int ret = 0; 182 183 /* 184 * If the condition variable is statically initialized, 185 * perform the dynamic initialization: 186 */ 187 if (__predict_false(*cond == NULL && 188 (ret = init_static(curthread, cond)) != 0)) 189 return (ret); 190 |
191 _thr_testcancel(curthread); 192 |
193 cv = *cond; 194 THR_UMUTEX_LOCK(curthread, &cv->c_lock); 195 ret = _mutex_cv_unlock(mutex, &info.count); 196 if (ret) { 197 THR_UMUTEX_UNLOCK(curthread, &cv->c_lock); 198 return (ret); 199 } 200 --- 4 unchanged lines hidden (view full) --- 205 clock_gettime(cv->c_clockid, &ts); 206 TIMESPEC_SUB(&ts2, abstime, &ts); 207 tsp = &ts2; 208 } else 209 tsp = NULL; 210 211 if (cancel) { 212 THR_CLEANUP_PUSH(curthread, cond_cancel_handler, &info); |
213 _thr_cancel_enter_defer(curthread, 0); |
214 ret = _thr_ucond_wait(&cv->c_kerncv, &cv->c_lock, tsp, 1); 215 info.cond = NULL; |
216 _thr_cancel_leave_defer(curthread, (ret != 0)); |
217 THR_CLEANUP_POP(curthread, 0); 218 } else { 219 ret = _thr_ucond_wait(&cv->c_kerncv, &cv->c_lock, tsp, 0); 220 } 221 if (ret == EINTR) 222 ret = 0; 223 _mutex_cv_lock(mutex, info.count); 224 return (ret); --- 78 unchanged lines hidden --- |