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 /**   Block Pool                                                          */
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 #include "tx_timer.h"
30 #include "tx_block_pool.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _txe_block_pool_delete                              PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    William E. Lamie, Microsoft Corporation                             */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function checks for errors in the delete block pool memory     */
46 /*    function call.                                                      */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    pool_ptr                          Pointer to pool control block     */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    TX_POOL_ERROR                     Invalid memory block pool pointer */
55 /*    TX_CALLER_ERROR                   Invalid caller of this function   */
56 /*    status                            Actual delete function status     */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _tx_block_pool_delete             Actual block pool delete 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_block_pool_delete(TX_BLOCK_POOL * pool_ptr)75 UINT    _txe_block_pool_delete(TX_BLOCK_POOL *pool_ptr)
76 {
77 
78 UINT        status;
79 #ifndef TX_TIMER_PROCESS_IN_ISR
80 TX_THREAD   *thread_ptr;
81 #endif
82 
83 
84 #ifndef TX_TIMER_PROCESS_IN_ISR
85 
86     /* Default status to success.  */
87     status =  TX_SUCCESS;
88 #endif
89 
90     /* Check for an invalid pool pointer.  */
91     if (pool_ptr == TX_NULL)
92     {
93 
94         /* Pool pointer is invalid, return appropriate error code.  */
95         status =  TX_POOL_ERROR;
96     }
97 
98     /* Now check the pool ID.  */
99     else if (pool_ptr -> tx_block_pool_id != TX_BLOCK_POOL_ID)
100     {
101 
102         /* Pool pointer is invalid, return appropriate error code.  */
103         status =  TX_POOL_ERROR;
104     }
105 
106     /* Check for invalid caller of this function.  */
107 
108     /* Is the call from an ISR or initialization?  */
109     else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
110     {
111 
112         /* Invalid caller of this function, return appropriate error code.  */
113         status =  TX_CALLER_ERROR;
114     }
115     else
116     {
117 
118 #ifndef TX_TIMER_PROCESS_IN_ISR
119 
120         /* Pickup thread pointer.  */
121         TX_THREAD_GET_CURRENT(thread_ptr)
122 
123         /* Is the call from the system timer thread?  */
124         if (thread_ptr == &_tx_timer_thread)
125         {
126 
127             /* Invalid caller of this function, return appropriate error code.  */
128             status =  TX_CALLER_ERROR;
129         }
130 
131         /* Determine if everything is okay.  */
132         if (status == TX_SUCCESS)
133         {
134 #endif
135 
136             /* Call actual block pool delete function.  */
137             status =  _tx_block_pool_delete(pool_ptr);
138 
139 #ifndef TX_TIMER_PROCESS_IN_ISR
140         }
141 #endif
142     }
143 
144     /* Return completion status.  */
145     return(status);
146 }
147 
148