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 /** ThreadX Component */
16 /** */
17 /** Thread */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define TX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "tx_api.h"
28 #include "tx_thread.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _txe_thread_terminate PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* William E. Lamie, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function checks for errors in the thread terminate function */
44 /* call. */
45 /* */
46 /* INPUT */
47 /* */
48 /* thread_ptr Pointer to thread to suspend */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* TX_THREAD_ERROR Invalid thread pointer */
53 /* TX_CALLER_ERROR Invalid caller of function */
54 /* status Actual completion status */
55 /* */
56 /* CALLS */
57 /* */
58 /* _tx_thread_terminate Actual thread terminate */
59 /* function */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* Application code */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
70 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
71 /* resulting in version 6.1 */
72 /* */
73 /**************************************************************************/
_txe_thread_terminate(TX_THREAD * thread_ptr)74 UINT _txe_thread_terminate(TX_THREAD *thread_ptr)
75 {
76
77 UINT status;
78
79
80 /* Check for an invalid thread pointer. */
81 if (thread_ptr == TX_NULL)
82 {
83
84 /* Thread pointer is invalid, return appropriate error code. */
85 status = TX_THREAD_ERROR;
86 }
87
88 /* Now check for invalid thread ID. */
89 else if (thread_ptr -> tx_thread_id != TX_THREAD_ID)
90 {
91
92 /* Thread pointer is invalid, return appropriate error code. */
93 status = TX_THREAD_ERROR;
94 }
95
96 /* Check for invalid caller of this function. */
97 else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
98 {
99
100 /* Invalid caller of this function, return appropriate error code. */
101 status = TX_CALLER_ERROR;
102 }
103 else
104 {
105
106 /* Call actual thread terminate function. */
107 status = _tx_thread_terminate(thread_ptr);
108 }
109
110 /* Return completion status. */
111 return(status);
112 }
113
114