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 /**   Queue                                                               */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  COMPONENT DEFINITION                                   RELEASE        */
26 /*                                                                        */
27 /*    tx_queue.h                                          PORTABLE C      */
28 /*                                                           6.1          */
29 /*  AUTHOR                                                                */
30 /*                                                                        */
31 /*    William E. Lamie, Microsoft Corporation                             */
32 /*                                                                        */
33 /*  DESCRIPTION                                                           */
34 /*                                                                        */
35 /*    This file defines the ThreadX queue management component,           */
36 /*    including all data types and external references.  It is assumed    */
37 /*    that tx_api.h and tx_port.h have already been included.             */
38 /*                                                                        */
39 /*  RELEASE HISTORY                                                       */
40 /*                                                                        */
41 /*    DATE              NAME                      DESCRIPTION             */
42 /*                                                                        */
43 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
44 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
45 /*                                            resulting in version 6.1    */
46 /*                                                                        */
47 /**************************************************************************/
48 
49 #ifndef TX_QUEUE_H
50 #define TX_QUEUE_H
51 
52 
53 /* Define queue control specific data definitions.  */
54 
55 #define TX_QUEUE_ID                             ((ULONG) 0x51554555)
56 
57 
58 /* Determine if in-line component initialization is supported by the
59    caller.  */
60 #ifdef TX_INVOKE_INLINE_INITIALIZATION
61 
62 /* Yes, in-line initialization is supported, remap the queue initialization
63    function.  */
64 
65 #ifndef TX_QUEUE_ENABLE_PERFORMANCE_INFO
66 #define _tx_queue_initialize() \
67                     _tx_queue_created_ptr =                          TX_NULL;     \
68                     _tx_queue_created_count =                        TX_EMPTY
69 #else
70 #define _tx_queue_initialize() \
71                     _tx_queue_created_ptr =                          TX_NULL;     \
72                     _tx_queue_created_count =                        TX_EMPTY;    \
73                     _tx_queue_performance_messages_sent_count =      ((ULONG) 0); \
74                     _tx_queue_performance__messages_received_count = ((ULONG) 0); \
75                     _tx_queue_performance_empty_suspension_count =   ((ULONG) 0); \
76                     _tx_queue_performance_full_suspension_count =    ((ULONG) 0); \
77                     _tx_queue_performance_timeout_count =            ((ULONG) 0)
78 #endif
79 #define TX_QUEUE_INIT
80 #else
81 
82 /* No in-line initialization is supported, use standard function call.  */
83 VOID        _tx_queue_initialize(VOID);
84 #endif
85 
86 
87 /* Define the message copy macro. Note that the source and destination
88    pointers must be modified since they are used subsequently.  */
89 
90 #ifndef TX_QUEUE_MESSAGE_COPY
91 #define TX_QUEUE_MESSAGE_COPY(s, d, z)          \
92                     *(d)++ = *(s)++;            \
93                     if ((z) > ((UINT) 1))       \
94                     {                           \
95                         while (--(z))           \
96                         {                       \
97                             *(d)++ =  *(s)++;   \
98                          }                      \
99                     }
100 #endif
101 
102 
103 /* Define internal queue management function prototypes.  */
104 
105 VOID        _tx_queue_cleanup(TX_THREAD *thread_ptr, ULONG suspension_sequence);
106 
107 
108 /* Queue management component data declarations follow.  */
109 
110 /* Determine if the initialization function of this component is including
111    this file.  If so, make the data definitions really happen.  Otherwise,
112    make them extern so other functions in the component can access them.  */
113 
114 #ifdef TX_QUEUE_INIT
115 #define QUEUE_DECLARE
116 #else
117 #define QUEUE_DECLARE extern
118 #endif
119 
120 
121 /* Define the head pointer of the created queue list.  */
122 
123 QUEUE_DECLARE  TX_QUEUE *   _tx_queue_created_ptr;
124 
125 
126 /* Define the variable that holds the number of created queues. */
127 
128 QUEUE_DECLARE  ULONG        _tx_queue_created_count;
129 
130 
131 #ifdef TX_QUEUE_ENABLE_PERFORMANCE_INFO
132 
133 /* Define the total number of messages sent.  */
134 
135 QUEUE_DECLARE  ULONG        _tx_queue_performance_messages_sent_count;
136 
137 
138 /* Define the total number of messages received.  */
139 
140 QUEUE_DECLARE  ULONG        _tx_queue_performance__messages_received_count;
141 
142 
143 /* Define the total number of queue empty suspensions.  */
144 
145 QUEUE_DECLARE  ULONG        _tx_queue_performance_empty_suspension_count;
146 
147 
148 /* Define the total number of queue full suspensions.  */
149 
150 QUEUE_DECLARE  ULONG        _tx_queue_performance_full_suspension_count;
151 
152 
153 /* Define the total number of queue full errors.  */
154 
155 QUEUE_DECLARE  ULONG        _tx_queue_performance_full_error_count;
156 
157 
158 /* Define the total number of queue timeouts.  */
159 
160 QUEUE_DECLARE  ULONG        _tx_queue_performance_timeout_count;
161 
162 
163 #endif
164 
165 
166 /* Define default post queue delete macro to whitespace, if it hasn't been defined previously (typically in tx_port.h).  */
167 
168 #ifndef TX_QUEUE_DELETE_PORT_COMPLETION
169 #define TX_QUEUE_DELETE_PORT_COMPLETION(q)
170 #endif
171 
172 
173 #endif
174 
175