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 /**   Semaphore                                                           */
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_semaphore.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _tx_semaphore_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 semaphore.   */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    semaphore_ptr                     Pointer to semaphore control block*/
49 /*    name                              Destination for the semaphore name*/
50 /*    current_value                     Destination for current value of  */
51 /*                                        the semaphore                   */
52 /*    first_suspended                   Destination for pointer of first  */
53 /*                                        thread suspended on semaphore   */
54 /*    suspended_count                   Destination for suspended count   */
55 /*    next_semaphore                    Destination for pointer to next   */
56 /*                                        semaphore 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_semaphore_info_get(TX_SEMAPHORE * semaphore_ptr,CHAR ** name,ULONG * current_value,TX_THREAD ** first_suspended,ULONG * suspended_count,TX_SEMAPHORE ** next_semaphore)79 UINT  _tx_semaphore_info_get(TX_SEMAPHORE *semaphore_ptr, CHAR **name, ULONG *current_value,
80                     TX_THREAD **first_suspended, ULONG *suspended_count,
81                     TX_SEMAPHORE **next_semaphore)
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_SEMAPHORE_INFO_GET, semaphore_ptr, 0, 0, 0, TX_TRACE_SEMAPHORE_EVENTS)
92 
93     /* Log this kernel call.  */
94     TX_EL_SEMAPHORE_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 semaphore.  */
100     if (name != TX_NULL)
101     {
102 
103         *name =  semaphore_ptr -> tx_semaphore_name;
104     }
105 
106     /* Retrieve the current value of the semaphore.  */
107     if (current_value != TX_NULL)
108     {
109 
110         *current_value =  semaphore_ptr -> tx_semaphore_count;
111     }
112 
113     /* Retrieve the first thread suspended on this semaphore.  */
114     if (first_suspended != TX_NULL)
115     {
116 
117         *first_suspended =  semaphore_ptr -> tx_semaphore_suspension_list;
118     }
119 
120     /* Retrieve the number of threads suspended on this semaphore.  */
121     if (suspended_count != TX_NULL)
122     {
123 
124         *suspended_count =  (ULONG) semaphore_ptr -> tx_semaphore_suspended_count;
125     }
126 
127     /* Retrieve the pointer to the next semaphore created.  */
128     if (next_semaphore != TX_NULL)
129     {
130 
131         *next_semaphore =  semaphore_ptr -> tx_semaphore_created_next;
132     }
133 
134     /* Restore interrupts.  */
135     TX_RESTORE
136 
137     /* Return completion status.  */
138     return(TX_SUCCESS);
139 }
140 
141