From eafdb5db2871e893574fd0da01554d1a50b7471f Mon Sep 17 00:00:00 2001 From: rpj Date: Fri, 24 Jul 1998 12:21:27 +0000 Subject: Fri Jul 24 21:13:55 1998 Ross Johnson * cancel.c (pthread_cancel): Implement. (pthread_testcancel): Implement. * exit.c (pthread_exit): Add comment explaining the longjmp(). * implement.h (_pthread_threads_thread_t): New member cancelthread. (_PTHREAD_YES): Define. (_PTHREAD_NO): Define. (RND_SIZEOF): Remove. * create.c (pthread_create): Rename cancelability to cancelstate. * pthread.h (pthread_attr_t): Rename cancelability to cancelstate. (PTHREAD_CANCELED): Define. --- cancel.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'cancel.c') diff --git a/cancel.c b/cancel.c index 72c41ad..e9e33f1 100644 --- a/cancel.c +++ b/cancel.c @@ -47,3 +47,41 @@ pthread_setcanceltype(int type, int *oldtype) this->canceltype = type; return 0; } + +int +pthread_cancel(pthread_t thread) +{ + _pthread_threads_thread_t * this; + + this = _PTHREAD_THIS; + + if (this == NULL) + { + return ESRCH; + } + + this->cancelthread = _PTHREAD_YES; + + return 0; +} + +void +pthread_testcancel(void) +{ + _pthread_threads_thread_t * this; + + this = _PTHREAD_THIS; + + if (this == NULL || + this->attr.cancelstate == PTHREAD_CANCEL_DISABLE) + { + return; + } + + if (this->cancelthread == _PTHREAD_YES) + { + pthread_exit(PTHREAD_CANCELED); + + /* Never reached. */ + } +} -- cgit v1.2.3