Deleted Added
full compact
thr_cond.c (177854) thr_cond.c (211524)
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 *
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 177854 2008-04-02 08:33:42Z davidxu $
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
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 */
165static int
166cond_wait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
167 const struct timespec *abstime, int cancel)
168{
169 struct pthread *curthread = _get_curthread();
170 struct timespec ts, ts2, *tsp;
171 struct cond_cancel_info info;
172 pthread_cond_t cv;
173 int ret = 0;
174
175 /*
176 * If the condition variable is statically initialized,
177 * perform the dynamic initialization:
178 */
179 if (__predict_false(*cond == NULL &&
180 (ret = init_static(curthread, cond)) != 0))
181 return (ret);
182
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
183 cv = *cond;
184 THR_UMUTEX_LOCK(curthread, &cv->c_lock);
185 ret = _mutex_cv_unlock(mutex, &info.count);
186 if (ret) {
187 THR_UMUTEX_UNLOCK(curthread, &cv->c_lock);
188 return (ret);
189 }
190

--- 4 unchanged lines hidden (view full) ---

195 clock_gettime(cv->c_clockid, &ts);
196 TIMESPEC_SUB(&ts2, abstime, &ts);
197 tsp = &ts2;
198 } else
199 tsp = NULL;
200
201 if (cancel) {
202 THR_CLEANUP_PUSH(curthread, cond_cancel_handler, &info);
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);
203 _thr_cancel_enter_defer(curthread);
213 _thr_cancel_enter_defer(curthread, 0);
204 ret = _thr_ucond_wait(&cv->c_kerncv, &cv->c_lock, tsp, 1);
205 info.cond = NULL;
214 ret = _thr_ucond_wait(&cv->c_kerncv, &cv->c_lock, tsp, 1);
215 info.cond = NULL;
206 _thr_cancel_leave_defer(curthread, ret);
216 _thr_cancel_leave_defer(curthread, (ret != 0));
207 THR_CLEANUP_POP(curthread, 0);
208 } else {
209 ret = _thr_ucond_wait(&cv->c_kerncv, &cv->c_lock, tsp, 0);
210 }
211 if (ret == EINTR)
212 ret = 0;
213 _mutex_cv_lock(mutex, info.count);
214 return (ret);

--- 78 unchanged lines hidden ---
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 ---