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 #define TX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "tx_api.h"
28 #include "tx_timer.h"
29 #include "tx_thread.h"
30 #include "tx_queue.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _txe_queue_delete                                   PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    William E. Lamie, Microsoft Corporation                             */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function checks for errors in the queue delete function call.  */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    queue_ptr                         Pointer to queue control block    */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    TX_QUEUE_ERROR                    Invalid queue pointer             */
54 /*    TX_CALLER_ERROR                   Invalid caller of this function   */
55 /*    status                            Actual completion status          */
56 /*                                                                        */
57 /*  CALLS                                                                 */
58 /*                                                                        */
59 /*    _tx_queue_delete                  Actual queue delete function      */
60 /*                                                                        */
61 /*  CALLED BY                                                             */
62 /*                                                                        */
63 /*    Application Code                                                    */
64 /*                                                                        */
65 /*  RELEASE HISTORY                                                       */
66 /*                                                                        */
67 /*    DATE              NAME                      DESCRIPTION             */
68 /*                                                                        */
69 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
70 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_txe_queue_delete(TX_QUEUE * queue_ptr)74 UINT  _txe_queue_delete(TX_QUEUE *queue_ptr)
75 {
76 
77 UINT            status;
78 #ifndef TX_TIMER_PROCESS_IN_ISR
79 TX_THREAD       *thread_ptr;
80 #endif
81 
82 
83     /* Default status to success.  */
84     status =  TX_SUCCESS;
85 
86     /* Check for an invalid queue pointer.  */
87     if (queue_ptr == TX_NULL)
88     {
89 
90         /* Queue pointer is invalid, return appropriate error code.  */
91         status =  TX_QUEUE_ERROR;
92     }
93 
94     /* Now check for a valid queue ID.  */
95     else if (queue_ptr -> tx_queue_id != TX_QUEUE_ID)
96     {
97 
98         /* Queue pointer is invalid, return appropriate error code.  */
99         status =  TX_QUEUE_ERROR;
100     }
101     else
102     {
103 
104         /* Check for invalid caller of this function.  */
105 
106         /* Is the caller an ISR or Initialization?  */
107         if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
108         {
109 
110             /* Invalid caller of this function, return appropriate error code.  */
111             status =  TX_CALLER_ERROR;
112         }
113 
114 #ifndef TX_TIMER_PROCESS_IN_ISR
115         else
116         {
117 
118             /* Pickup thread pointer.  */
119             TX_THREAD_GET_CURRENT(thread_ptr)
120 
121             /* Is the caller the system timer thread?  */
122             if (thread_ptr == &_tx_timer_thread)
123             {
124 
125                 /* Invalid caller of this function, return appropriate error code.  */
126                 status =  TX_CALLER_ERROR;
127             }
128         }
129 #endif
130     }
131 
132     /* Determine if everything is okay.  */
133     if (status == TX_SUCCESS)
134     {
135 
136         /* Call actual queue delete function.  */
137         status =  _tx_queue_delete(queue_ptr);
138     }
139 
140     /* Return completion status.  */
141     return(status);
142 }
143 
144