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 /**   Byte Memory                                                         */
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_initialize.h"
29 #include "tx_thread.h"
30 #include "tx_timer.h"
31 #include "tx_byte_pool.h"
32 
33 
34 /**************************************************************************/
35 /*                                                                        */
36 /*  FUNCTION                                               RELEASE        */
37 /*                                                                        */
38 /*    _txe_byte_release                                   PORTABLE C      */
39 /*                                                           6.1          */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    William E. Lamie, Microsoft Corporation                             */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function checks for errors in the release byte function call.  */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    memory_ptr                        Pointer to allocated memory       */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    TX_PTR_ERROR                      Invalid memory pointer            */
55 /*    TX_CALLER_ERROR                   Invalid caller of this function   */
56 /*    status                            Actual completion status          */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _tx_byte_release                  Actual byte release function      */
61 /*                                                                        */
62 /*  CALLED BY                                                             */
63 /*                                                                        */
64 /*    Application Code                                                    */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
71 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*                                                                        */
74 /**************************************************************************/
_txe_byte_release(VOID * memory_ptr)75 UINT  _txe_byte_release(VOID *memory_ptr)
76 {
77 
78 UINT            status;
79 #ifndef TX_TIMER_PROCESS_IN_ISR
80 TX_THREAD       *thread_ptr;
81 #endif
82 
83 
84     /* Default status to success.  */
85     status =  TX_SUCCESS;
86 
87     /* First check the supplied memory pointer.  */
88     if (memory_ptr == TX_NULL)
89     {
90 
91         /* The byte memory pointer is invalid, return appropriate status.  */
92         status =  TX_PTR_ERROR;
93     }
94     else
95     {
96 
97 #ifndef TX_TIMER_PROCESS_IN_ISR
98 
99         /* Pickup thread pointer.  */
100         TX_THREAD_GET_CURRENT(thread_ptr)
101 
102         /* Check for invalid caller of this function.  First check for a calling thread.  */
103         if (thread_ptr == &_tx_timer_thread)
104         {
105 
106             /* Invalid caller of this function, return appropriate error code.  */
107             status =  TX_CALLER_ERROR;
108         }
109 #endif
110 
111         /* Check for interrupt call.  */
112         if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
113         {
114 
115             /* Now, make sure the call is from an interrupt and not initialization.  */
116             if (TX_THREAD_GET_SYSTEM_STATE() < TX_INITIALIZE_IN_PROGRESS)
117             {
118 
119                 /* Invalid caller of this function, return appropriate error code.  */
120                 status =  TX_CALLER_ERROR;
121             }
122         }
123     }
124 
125     /* Determine if everything is okay.  */
126     if (status == TX_SUCCESS)
127     {
128 
129         /* Call actual byte release function.  */
130         status =  _tx_byte_release(memory_ptr);
131     }
132 
133     /* Return completion status.  */
134     return(status);
135 }
136 
137