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 /**   Event Flags                                                         */
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_event_flags.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _tx_event_flags_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 event flag   */
45 /*    group.                                                              */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    group_ptr                         Pointer to event flag group       */
50 /*    name                              Destination for the event flag    */
51 /*                                        group name                      */
52 /*    current_flags                     Current event flags               */
53 /*    first_suspended                   Destination for pointer of first  */
54 /*                                        thread suspended on event flags */
55 /*    suspended_count                   Destination for suspended count   */
56 /*    next_group                        Destination for pointer to next   */
57 /*                                        event flag group on the created */
58 /*                                        list                            */
59 /*                                                                        */
60 /*  OUTPUT                                                                */
61 /*                                                                        */
62 /*    status                            Completion status                 */
63 /*                                                                        */
64 /*  CALLS                                                                 */
65 /*                                                                        */
66 /*    None                                                                */
67 /*                                                                        */
68 /*  CALLED BY                                                             */
69 /*                                                                        */
70 /*    Application Code                                                    */
71 /*                                                                        */
72 /*  RELEASE HISTORY                                                       */
73 /*                                                                        */
74 /*    DATE              NAME                      DESCRIPTION             */
75 /*                                                                        */
76 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
77 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
78 /*                                            resulting in version 6.1    */
79 /*                                                                        */
80 /**************************************************************************/
_tx_event_flags_info_get(TX_EVENT_FLAGS_GROUP * group_ptr,CHAR ** name,ULONG * current_flags,TX_THREAD ** first_suspended,ULONG * suspended_count,TX_EVENT_FLAGS_GROUP ** next_group)81 UINT  _tx_event_flags_info_get(TX_EVENT_FLAGS_GROUP *group_ptr, CHAR **name, ULONG *current_flags,
82                     TX_THREAD **first_suspended, ULONG *suspended_count,
83                     TX_EVENT_FLAGS_GROUP **next_group)
84 {
85 
86 TX_INTERRUPT_SAVE_AREA
87 
88 
89     /* Disable interrupts.  */
90     TX_DISABLE
91 
92     /* If trace is enabled, insert this event into the trace buffer.  */
93     TX_TRACE_IN_LINE_INSERT(TX_TRACE_EVENT_FLAGS_INFO_GET, group_ptr, 0, 0, 0, TX_TRACE_EVENT_FLAGS_EVENTS)
94 
95     /* Log this kernel call.  */
96     TX_EL_EVENT_FLAGS_INFO_GET_INSERT
97 
98     /* Retrieve all the pertinent information and return it in the supplied
99        destinations.  */
100 
101     /* Retrieve the name of the event flag group.  */
102     if (name != TX_NULL)
103     {
104 
105         *name =  group_ptr -> tx_event_flags_group_name;
106     }
107 
108     /* Retrieve the current event flags in the event flag group.  */
109     if (current_flags != TX_NULL)
110     {
111 
112         /* Pickup the current flags and apply delayed clearing.  */
113         *current_flags =  group_ptr -> tx_event_flags_group_current &
114                                                         ~group_ptr -> tx_event_flags_group_delayed_clear;
115     }
116 
117     /* Retrieve the first thread suspended on this event flag group.  */
118     if (first_suspended != TX_NULL)
119     {
120 
121         *first_suspended =  group_ptr -> tx_event_flags_group_suspension_list;
122     }
123 
124     /* Retrieve the number of threads suspended on this event flag group.  */
125     if (suspended_count != TX_NULL)
126     {
127 
128         *suspended_count =  (ULONG) group_ptr -> tx_event_flags_group_suspended_count;
129     }
130 
131     /* Retrieve the pointer to the next event flag group created.  */
132     if (next_group != TX_NULL)
133     {
134 
135         *next_group =  group_ptr -> tx_event_flags_group_created_next;
136     }
137 
138     /* Restore interrupts.  */
139     TX_RESTORE
140 
141     /* Return completion status.  */
142     return(TX_SUCCESS);
143 }
144 
145