1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
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_testcancel PORTABLE C */
34 /* 6.1.7 */
35 /* AUTHOR */
36 /* */
37 /* William E. Lamie, Microsoft Corporation */
38 /* */
39 /* DESCRIPTION */
40 /* */
41 /* The pthread_testcancel function shall request that thread be */
42 /* canceled if the cancel state is enabled and cancel type is */
43 /* deferred, and a cancellation request has happened in the past. */
44 /* The target thread's cancelability state and type determines when */
45 /* the cancellation takes effect. When the cancellation is acted on, */
46 /* the cancelation cleanup handlers for thread shall be called. When */
47 /* the last cancelation cleanup handler returns, the thread-specific */
48 /* data destructor functions shall be called for thread. When the last */
49 /* destructor function returns, thread shall be terminated. */
50 /* */
51 /* INPUT */
52 /* */
53 /* thread pthread handle to thread to be canceled */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* */
58 /* */
59 /* CALLS */
60 /* posix_destroy_thread */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* Application Code */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
71 /* */
72 /**************************************************************************/
pthread_testcancel(VOID)73 VOID pthread_testcancel(VOID)
74 {
75
76 POSIX_TCB *pthread_ptr;
77
78
79 /* Get the thread identifier of the calling pthread */
80 pthread_ptr = posix_tid2tcb(pthread_self());
81
82 /* Check if thread was created with cancel enable */
83 if ( (pthread_ptr->cancel_state == PTHREAD_CANCEL_ENABLE) &&
84 (pthread_ptr->cancel_type==PTHREAD_CANCEL_DEFERRED) &&
85 (pthread_ptr->cancel_request==TRUE) )
86 {
87
88 /* Signal the housekeeping ThreadX thread to cancel (delete) this pthread */
89 posix_destroy_pthread(pthread_ptr,(VOID *)0);
90 }
91 }
92
93