1 /* 2 * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "pthread_private.h" 8 9 #include <stdio.h> 10 11 12 int 13 pthread_cancel(pthread_t thread) 14 { 15 // TODO: notify thread of being cancelled. 16 fprintf(stderr, "pthread_cancel() is not yet implemented!\n"); 17 return EINVAL; 18 } 19 20 21 int 22 pthread_setcancelstate(int state, int *_oldState) 23 { 24 if (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE) 25 return EINVAL; 26 27 pthread_thread* thread = pthread_self(); 28 if (thread == NULL) 29 return EINVAL; 30 31 if (_oldState != NULL) 32 *_oldState = thread->cancel_state; 33 34 thread->cancel_state = state; 35 return 0; 36 } 37 38 39 int 40 pthread_setcanceltype(int type, int *_oldType) 41 { 42 if (type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS) 43 return EINVAL; 44 45 pthread_thread* thread = pthread_self(); 46 if (thread == NULL) 47 return EINVAL; 48 49 if (_oldType != NULL) 50 *_oldType = thread->cancel_type; 51 52 thread->cancel_type = type; 53 return 0; 54 } 55 56 57 void 58 pthread_testcancel(void) 59 { 60 pthread_thread* thread = pthread_self(); 61 if (thread == NULL) 62 return; 63 64 if (thread->cancelled && thread->cancel_state == PTHREAD_CANCEL_ENABLE) 65 pthread_exit(NULL); 66 } 67 68