thr_cancel.c (113658) | thr_cancel.c (114187) |
---|---|
1/* 2 * David Leonard <d@openbsd.org>, 1999. Public domain. | 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 $ | 3 * $FreeBSD: head/lib/libkse/thread/thr_cancel.c 114187 2003-04-28 23:56:12Z 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: */ | 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 } | 220 221 if (checkcancel(curthread) != 0) { 222 /* Unlock before exiting: */ 223 THR_SCHED_UNLOCK(curthread, curthread); 224 225 _thr_exit_cleanup(); 226 pthread_exit(PTHREAD_CANCELED); 227 PANIC("cancel"); 228 } |
230 231 THR_SCHED_UNLOCK(curthread, curthread); | |
232} 233 234void 235_pthread_testcancel(void) 236{ 237 struct pthread *curthread = _get_curthread(); 238 | 229} 230 231void 232_pthread_testcancel(void) 233{ 234 struct pthread *curthread = _get_curthread(); 235 |
236 THR_SCHED_LOCK(curthread, curthread); |
|
239 testcancel(curthread); | 237 testcancel(curthread); |
238 THR_SCHED_UNLOCK(curthread, curthread); |
|
240} 241 242void 243_thr_enter_cancellation_point(struct pthread *thread) 244{ 245 /* Look for a cancellation before we block: */ | 239} 240 241void 242_thr_enter_cancellation_point(struct pthread *thread) 243{ 244 /* Look for a cancellation before we block: */ |
245 THR_SCHED_LOCK(thread, thread); |
|
246 testcancel(thread); 247 thread->cancelflags |= THR_AT_CANCEL_POINT; | 246 testcancel(thread); 247 thread->cancelflags |= THR_AT_CANCEL_POINT; |
248 THR_SCHED_UNLOCK(thread, thread); |
|
248} 249 250void 251_thr_leave_cancellation_point(struct pthread *thread) 252{ | 249} 250 251void 252_thr_leave_cancellation_point(struct pthread *thread) 253{ |
254 THR_SCHED_LOCK(thread, thread); |
|
253 thread->cancelflags &= ~THR_AT_CANCEL_POINT; 254 /* Look for a cancellation after we unblock: */ 255 testcancel(thread); | 255 thread->cancelflags &= ~THR_AT_CANCEL_POINT; 256 /* Look for a cancellation after we unblock: */ 257 testcancel(thread); |
258 THR_SCHED_UNLOCK(thread, 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 | 259} 260 261static void 262finish_cancellation(void *arg) 263{ 264 struct pthread *curthread = _get_curthread(); 265 266 curthread->continuation = NULL; 267 curthread->interrupted = 0; 268 |
269 THR_SCHED_LOCK(curthread, curthread); |
|
266 if ((curthread->cancelflags & THR_CANCEL_NEEDED) != 0) { 267 curthread->cancelflags &= ~THR_CANCEL_NEEDED; | 270 if ((curthread->cancelflags & THR_CANCEL_NEEDED) != 0) { 271 curthread->cancelflags &= ~THR_CANCEL_NEEDED; |
272 THR_SCHED_UNLOCK(curthread, curthread); |
|
268 _thr_exit_cleanup(); 269 pthread_exit(PTHREAD_CANCELED); 270 } | 273 _thr_exit_cleanup(); 274 pthread_exit(PTHREAD_CANCELED); 275 } |
276 THR_SCHED_UNLOCK(curthread, curthread); |
|
271} | 277} |