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 /** Mutex */ 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_mutex.h" 32 33 34 /**************************************************************************/ 35 /* */ 36 /* FUNCTION RELEASE */ 37 /* */ 38 /* _txe_mutex_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 mutex delete function */ 47 /* call. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* mutex_ptr Pointer to mutex control block */ 52 /* */ 53 /* OUTPUT */ 54 /* */ 55 /* TX_MUTEX_ERROR Invalid mutex pointer */ 56 /* TX_CALLER_ERROR Invalid caller of this function */ 57 /* status Actual completion status */ 58 /* */ 59 /* CALLS */ 60 /* */ 61 /* _tx_mutex_delete Actual delete mutex 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_mutex_delete(TX_MUTEX * mutex_ptr)76UINT _txe_mutex_delete(TX_MUTEX *mutex_ptr) 77 { 78 79 UINT status; 80 #ifndef TX_TIMER_PROCESS_IN_ISR 81 TX_THREAD *thread_ptr; 82 #endif 83 84 85 #ifndef TX_TIMER_PROCESS_IN_ISR 86 87 /* Default status to success. */ 88 status = TX_SUCCESS; 89 #endif 90 91 /* Check for an invalid mutex pointer. */ 92 if (mutex_ptr == TX_NULL) 93 { 94 95 /* Mutex pointer is invalid, return appropriate error code. */ 96 status = TX_MUTEX_ERROR; 97 } 98 99 /* Now check for a valid mutex ID. */ 100 else if (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID) 101 { 102 103 /* Mutex pointer is invalid, return appropriate error code. */ 104 status = TX_MUTEX_ERROR; 105 } 106 107 /* Check for invalid caller of this function. */ 108 109 /* Is the caller an ISR or Initialization? */ 110 else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0)) 111 { 112 113 /* Invalid caller of this function, return appropriate error code. */ 114 status = TX_CALLER_ERROR; 115 } 116 else 117 { 118 119 #ifndef TX_TIMER_PROCESS_IN_ISR 120 121 /* Pickup thread pointer. */ 122 TX_THREAD_GET_CURRENT(thread_ptr) 123 124 /* Is the caller the system timer thread? */ 125 if (thread_ptr == &_tx_timer_thread) 126 { 127 128 /* Invalid caller of this function, return appropriate error code. */ 129 status = TX_CALLER_ERROR; 130 } 131 132 /* Determine if everything is okay. */ 133 if (status == TX_SUCCESS) 134 { 135 #endif 136 137 /* Call actual mutex delete function. */ 138 status = _tx_mutex_delete(mutex_ptr); 139 140 #ifndef TX_TIMER_PROCESS_IN_ISR 141 } 142 #endif 143 } 144 145 /* Return completion status. */ 146 return(status); 147 } 148 149