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 /** Mutex */ 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_initialize.h" 29 #include "tx_thread.h" 30 #include "tx_mutex.h" 31 32 33 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _txe_mutex_put 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 mutex put function call. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* mutex_ptr Pointer to mutex control block */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* TX_MUTEX_ERROR Invalid mutex pointer */ 54 /* status Actual completion status */ 55 /* */ 56 /* CALLS */ 57 /* */ 58 /* _tx_mutex_put Actual put mutex function */ 59 /* */ 60 /* CALLED BY */ 61 /* */ 62 /* Application Code */ 63 /* */ 64 /* RELEASE HISTORY */ 65 /* */ 66 /* DATE NAME DESCRIPTION */ 67 /* */ 68 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 69 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 70 /* resulting in version 6.1 */ 71 /* */ 72 /**************************************************************************/ _txe_mutex_put(TX_MUTEX * mutex_ptr)73UINT _txe_mutex_put(TX_MUTEX *mutex_ptr) 74 { 75 76 UINT status; 77 78 79 /* Default status to success. */ 80 status = TX_SUCCESS; 81 82 /* Check for an invalid mutex pointer. */ 83 if (mutex_ptr == TX_NULL) 84 { 85 86 /* Mutex pointer is invalid, return appropriate error code. */ 87 status = TX_MUTEX_ERROR; 88 } 89 90 /* Now check for invalid mutex ID. */ 91 else if (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID) 92 { 93 94 /* Mutex pointer is invalid, return appropriate error code. */ 95 status = TX_MUTEX_ERROR; 96 } 97 else 98 { 99 100 /* Check for interrupt call. */ 101 if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0)) 102 { 103 104 /* Now, make sure the call is from an interrupt and not initialization. */ 105 if (TX_THREAD_GET_SYSTEM_STATE() < TX_INITIALIZE_IN_PROGRESS) 106 { 107 108 /* Invalid caller of this function, return appropriate error code. */ 109 status = TX_CALLER_ERROR; 110 } 111 } 112 } 113 114 /* Determine if everything is okay. */ 115 if (status == TX_SUCCESS) 116 { 117 118 /* Call actual put mutex function. */ 119 status = _tx_mutex_put(mutex_ptr); 120 } 121 122 /* Return completion status. */ 123 return(status); 124 } 125 126