1 /*************************************************************************** 2 * Copyright (c) 2024 Microsoft Corporation 3 * 4 * This program and the accompanying materials are made available under the 5 * terms of the MIT License which is available at 6 * https://opensource.org/licenses/MIT. 7 * 8 * SPDX-License-Identifier: MIT 9 **************************************************************************/ 10 11 12 /**************************************************************************/ 13 /**************************************************************************/ 14 /** */ 15 /** POSIX wrapper for THREADX */ 16 /** */ 17 /** */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 /* Include necessary system files. */ 23 24 #include "tx_api.h" /* Threadx API */ 25 #include "pthread.h" /* Posix API */ 26 #include "px_int.h" /* Posix helper functions */ 27 28 29 /**************************************************************************/ 30 /* */ 31 /* FUNCTION RELEASE */ 32 /* */ 33 /* pthread_setcancelstate PORTABLE C */ 34 /* 6.1.7 */ 35 /* AUTHOR */ 36 /* */ 37 /* William E. Lamie, Microsoft Corporation */ 38 /* */ 39 /* DESCRIPTION */ 40 /* */ 41 /* The pthread_setcancelstate()function shall atomically both set the */ 42 /* calling thread�s cancelability state to the indicated state and */ 43 /* return the previous cancelability state at the location referenced */ 44 /* by oldstate.Legal values for state are PTHREAD_CANCEL_ENABLE and */ 45 /* PTHREAD_CANCEL_DISABLE. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* state New cancelability state to be set */ 50 /* oldstate Pointer to old cancelability state */ 51 /* */ 52 /* OUTPUT */ 53 /* */ 54 /* 0 if successful */ 55 /* Value in case of any error */ 56 /* */ 57 /* CALLS */ 58 /* */ 59 /* None */ 60 /* */ 61 /* CALLED BY */ 62 /* */ 63 /* Application Code */ 64 /* */ 65 /* RELEASE HISTORY */ 66 /* */ 67 /* DATE NAME DESCRIPTION */ 68 /* */ 69 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ 70 /* */ 71 /**************************************************************************/ pthread_setcancelstate(INT state,INT * oldstate)72INT pthread_setcancelstate (INT state, INT *oldstate) 73 { 74 75 TX_INTERRUPT_SAVE_AREA 76 77 TX_THREAD *thread_ptr; 78 POSIX_TCB *pthread_ptr; 79 80 /* First check for validity of the new cancel state to be set */ 81 if ( (state == PTHREAD_CANCEL_ENABLE) || (state == PTHREAD_CANCEL_DISABLE) ) 82 { 83 TX_DISABLE 84 85 /* Get the thread identifier of the currently running thread */ 86 thread_ptr = tx_thread_identify(); 87 /* get posix TCB for this pthread */ 88 pthread_ptr = (POSIX_TCB *)thread_ptr; 89 *oldstate = pthread_ptr->cancel_state; 90 pthread_ptr->cancel_state = state; 91 92 TX_RESTORE 93 94 return(OK); 95 } 96 else 97 { 98 posix_errno = EINVAL; 99 posix_set_pthread_errno(EINVAL); 100 return (EINVAL); 101 } 102 } 103