Deleted Added
sdiff udiff text old ( 113658 ) new ( 114187 )
full compact
1/*
2 * David Leonard <d@openbsd.org>, 1999. Public domain.
3 * $FreeBSD: head/lib/libkse/thread/thr_cancel.c 113658 2003-04-18 05:04:16Z deischen $
4 */
5#include <sys/errno.h>
6#include <pthread.h>
7#include "thr_private.h"
8
9__weak_reference(_pthread_cancel, pthread_cancel);
10__weak_reference(_pthread_setcancelstate, pthread_setcancelstate);
11__weak_reference(_pthread_setcanceltype, pthread_setcanceltype);

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

212 else
213 return (0);
214}
215
216static void
217testcancel(struct pthread *curthread)
218{
219 /* Take the scheduling lock while fiddling with the state: */
220 THR_SCHED_LOCK(curthread, curthread);
221
222 if (checkcancel(curthread) != 0) {
223 /* Unlock before exiting: */
224 THR_SCHED_UNLOCK(curthread, curthread);
225
226 _thr_exit_cleanup();
227 pthread_exit(PTHREAD_CANCELED);
228 PANIC("cancel");
229 }
230
231 THR_SCHED_UNLOCK(curthread, curthread);
232}
233
234void
235_pthread_testcancel(void)
236{
237 struct pthread *curthread = _get_curthread();
238
239 testcancel(curthread);
240}
241
242void
243_thr_enter_cancellation_point(struct pthread *thread)
244{
245 /* Look for a cancellation before we block: */
246 testcancel(thread);
247 thread->cancelflags |= THR_AT_CANCEL_POINT;
248}
249
250void
251_thr_leave_cancellation_point(struct pthread *thread)
252{
253 thread->cancelflags &= ~THR_AT_CANCEL_POINT;
254 /* Look for a cancellation after we unblock: */
255 testcancel(thread);
256}
257
258static void
259finish_cancellation(void *arg)
260{
261 struct pthread *curthread = _get_curthread();
262
263 curthread->continuation = NULL;
264 curthread->interrupted = 0;
265
266 if ((curthread->cancelflags & THR_CANCEL_NEEDED) != 0) {
267 curthread->cancelflags &= ~THR_CANCEL_NEEDED;
268 _thr_exit_cleanup();
269 pthread_exit(PTHREAD_CANCELED);
270 }
271}