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