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_trace.h"
29 #include "tx_byte_pool.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _tx_byte_pool_info_get                              PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    William E. Lamie, Microsoft Corporation                             */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function retrieves information from the specified byte pool.   */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    pool_ptr                          Pointer to byte pool control block*/
49 /*    name                              Destination for the pool name     */
50 /*    available_bytes                   Number of free bytes in byte pool */
51 /*    fragments                         Number of fragments in byte pool  */
52 /*    first_suspended                   Destination for pointer of first  */
53 /*                                        thread suspended on byte pool   */
54 /*    suspended_count                   Destination for suspended count   */
55 /*    next_pool                         Destination for pointer to next   */
56 /*                                        byte pool on the created list   */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    status                            Completion status                 */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*    None                                                                */
65 /*                                                                        */
66 /*  CALLED BY                                                             */
67 /*                                                                        */
68 /*    Application Code                                                    */
69 /*                                                                        */
70 /*  RELEASE HISTORY                                                       */
71 /*                                                                        */
72 /*    DATE              NAME                      DESCRIPTION             */
73 /*                                                                        */
74 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
75 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
76 /*                                            resulting in version 6.1    */
77 /*                                                                        */
78 /**************************************************************************/
_tx_byte_pool_info_get(TX_BYTE_POOL * pool_ptr,CHAR ** name,ULONG * available_bytes,ULONG * fragments,TX_THREAD ** first_suspended,ULONG * suspended_count,TX_BYTE_POOL ** next_pool)79 UINT  _tx_byte_pool_info_get(TX_BYTE_POOL *pool_ptr, CHAR **name, ULONG *available_bytes,
80                     ULONG *fragments, TX_THREAD **first_suspended,
81                     ULONG *suspended_count, TX_BYTE_POOL **next_pool)
82 {
83 
84 TX_INTERRUPT_SAVE_AREA
85 
86 
87     /* Disable interrupts.  */
88     TX_DISABLE
89 
90     /* If trace is enabled, insert this event into the trace buffer.  */
91     TX_TRACE_IN_LINE_INSERT(TX_TRACE_BYTE_POOL_INFO_GET, pool_ptr, 0, 0, 0, TX_TRACE_BYTE_POOL_EVENTS)
92 
93     /* Log this kernel call.  */
94     TX_EL_BYTE_POOL_INFO_GET_INSERT
95 
96     /* Retrieve all the pertinent information and return it in the supplied
97        destinations.  */
98 
99     /* Retrieve the name of the byte pool.  */
100     if (name != TX_NULL)
101     {
102 
103         *name =  pool_ptr -> tx_byte_pool_name;
104     }
105 
106     /* Retrieve the number of available bytes in the byte pool.  */
107     if (available_bytes != TX_NULL)
108     {
109 
110         *available_bytes =  pool_ptr -> tx_byte_pool_available;
111     }
112 
113     /* Retrieve the total number of bytes in the byte pool.  */
114     if (fragments != TX_NULL)
115     {
116 
117         *fragments =  (ULONG) pool_ptr -> tx_byte_pool_fragments;
118     }
119 
120     /* Retrieve the first thread suspended on this byte pool.  */
121     if (first_suspended != TX_NULL)
122     {
123 
124         *first_suspended =  pool_ptr -> tx_byte_pool_suspension_list;
125     }
126 
127     /* Retrieve the number of threads suspended on this byte pool.  */
128     if (suspended_count != TX_NULL)
129     {
130 
131         *suspended_count =  (ULONG) pool_ptr -> tx_byte_pool_suspended_count;
132     }
133 
134     /* Retrieve the pointer to the next byte pool created.  */
135     if (next_pool != TX_NULL)
136     {
137 
138         *next_pool =  pool_ptr -> tx_byte_pool_created_next;
139     }
140 
141     /* Restore interrupts.  */
142     TX_RESTORE
143 
144     /* Return completion status.  */
145     return(TX_SUCCESS);
146 }
147 
148