1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** ThreadX Component */
17 /** */
18 /** Semaphore */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define TX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "tx_api.h"
29 #include "tx_trace.h"
30 #include "tx_semaphore.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _tx_semaphore_info_get PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* William E. Lamie, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function retrieves information from the specified semaphore. */
46 /* */
47 /* INPUT */
48 /* */
49 /* semaphore_ptr Pointer to semaphore control block*/
50 /* name Destination for the semaphore name*/
51 /* current_value Destination for current value of */
52 /* the semaphore */
53 /* first_suspended Destination for pointer of first */
54 /* thread suspended on semaphore */
55 /* suspended_count Destination for suspended count */
56 /* next_semaphore Destination for pointer to next */
57 /* semaphore on the created list */
58 /* */
59 /* OUTPUT */
60 /* */
61 /* status Completion status */
62 /* */
63 /* CALLS */
64 /* */
65 /* None */
66 /* */
67 /* CALLED BY */
68 /* */
69 /* Application Code */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
76 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
77 /* resulting in version 6.1 */
78 /* */
79 /**************************************************************************/
_tx_semaphore_info_get(TX_SEMAPHORE * semaphore_ptr,CHAR ** name,ULONG * current_value,TX_THREAD ** first_suspended,ULONG * suspended_count,TX_SEMAPHORE ** next_semaphore)80 UINT _tx_semaphore_info_get(TX_SEMAPHORE *semaphore_ptr, CHAR **name, ULONG *current_value,
81 TX_THREAD **first_suspended, ULONG *suspended_count,
82 TX_SEMAPHORE **next_semaphore)
83 {
84
85 TX_INTERRUPT_SAVE_AREA
86
87
88 /* Disable interrupts. */
89 TX_DISABLE
90
91 /* If trace is enabled, insert this event into the trace buffer. */
92 TX_TRACE_IN_LINE_INSERT(TX_TRACE_SEMAPHORE_INFO_GET, semaphore_ptr, 0, 0, 0, TX_TRACE_SEMAPHORE_EVENTS)
93
94 /* Log this kernel call. */
95 TX_EL_SEMAPHORE_INFO_GET_INSERT
96
97 /* Retrieve all the pertinent information and return it in the supplied
98 destinations. */
99
100 /* Retrieve the name of the semaphore. */
101 if (name != TX_NULL)
102 {
103
104 *name = semaphore_ptr -> tx_semaphore_name;
105 }
106
107 /* Retrieve the current value of the semaphore. */
108 if (current_value != TX_NULL)
109 {
110
111 *current_value = semaphore_ptr -> tx_semaphore_count;
112 }
113
114 /* Retrieve the first thread suspended on this semaphore. */
115 if (first_suspended != TX_NULL)
116 {
117
118 *first_suspended = semaphore_ptr -> tx_semaphore_suspension_list;
119 }
120
121 /* Retrieve the number of threads suspended on this semaphore. */
122 if (suspended_count != TX_NULL)
123 {
124
125 *suspended_count = (ULONG) semaphore_ptr -> tx_semaphore_suspended_count;
126 }
127
128 /* Retrieve the pointer to the next semaphore created. */
129 if (next_semaphore != TX_NULL)
130 {
131
132 *next_semaphore = semaphore_ptr -> tx_semaphore_created_next;
133 }
134
135 /* Restore interrupts. */
136 TX_RESTORE
137
138 /* Return completion status. */
139 return(TX_SUCCESS);
140 }
141
142