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_trace.h"
29 #include "tx_thread.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _tx_thread_entry_exit_notify PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* William E. Lamie, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function registers an application entry/exit notification */
45 /* callback routine for the application. Once registered, the callback */
46 /* routine is called when the thread is initially entered and called */
47 /* again when the thread completes or is terminated. */
48 /* */
49 /* INPUT */
50 /* */
51 /* thread_ptr Pointer to thread */
52 /* thread_entry_exit_notify Pointer to notify callback */
53 /* function, TX_NULL to disable*/
54 /* */
55 /* OUTPUT */
56 /* */
57 /* status Service return status */
58 /* */
59 /* CALLS */
60 /* */
61 /* None */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Application Code */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
72 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
73 /* resulting in version 6.1 */
74 /* */
75 /**************************************************************************/
_tx_thread_entry_exit_notify(TX_THREAD * thread_ptr,VOID (* thread_entry_exit_notify)(TX_THREAD * notify_thread_ptr,UINT id))76 UINT _tx_thread_entry_exit_notify(TX_THREAD *thread_ptr, VOID (*thread_entry_exit_notify)(TX_THREAD *notify_thread_ptr, UINT id))
77 {
78
79 #ifdef TX_DISABLE_NOTIFY_CALLBACKS
80
81 TX_THREAD_NOT_USED(thread_ptr);
82 TX_THREAD_ENTRY_EXIT_NOTIFY_NOT_USED(thread_entry_exit_notify);
83
84 /* Feature is not enabled, return error. */
85 return(TX_FEATURE_NOT_ENABLED);
86 #else
87
88 TX_INTERRUPT_SAVE_AREA
89
90
91 /* Disable interrupts. */
92 TX_DISABLE
93
94 /* Make entry in event log. */
95 TX_TRACE_IN_LINE_INSERT(TX_TRACE_THREAD_ENTRY_EXIT_NOTIFY, thread_ptr, thread_ptr -> tx_thread_state, 0, 0, TX_TRACE_THREAD_EVENTS)
96
97 /* Make entry in event log. */
98 TX_EL_THREAD_ENTRY_EXIT_NOTIFY_INSERT
99
100 /* Setup thread entry/exit notification callback function. */
101 thread_ptr -> tx_thread_entry_exit_notify = thread_entry_exit_notify;
102
103 /* Restore interrupts. */
104 TX_RESTORE
105
106 /* Return success to caller. */
107 return(TX_SUCCESS);
108 #endif
109 }
110
111