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_initialize.h"
30 #include "tx_thread.h"
31 #include "tx_mutex.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _txe_mutex_put 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 put function call. */
47 /* */
48 /* INPUT */
49 /* */
50 /* mutex_ptr Pointer to mutex control block */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* TX_MUTEX_ERROR Invalid mutex pointer */
55 /* status Actual completion status */
56 /* */
57 /* CALLS */
58 /* */
59 /* _tx_mutex_put Actual put mutex 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_mutex_put(TX_MUTEX * mutex_ptr)74 UINT _txe_mutex_put(TX_MUTEX *mutex_ptr)
75 {
76
77 UINT status;
78
79
80 /* Default status to success. */
81 status = TX_SUCCESS;
82
83 /* Check for an invalid mutex pointer. */
84 if (mutex_ptr == TX_NULL)
85 {
86
87 /* Mutex pointer is invalid, return appropriate error code. */
88 status = TX_MUTEX_ERROR;
89 }
90
91 /* Now check for invalid mutex ID. */
92 else if (mutex_ptr -> tx_mutex_id != TX_MUTEX_ID)
93 {
94
95 /* Mutex pointer is invalid, return appropriate error code. */
96 status = TX_MUTEX_ERROR;
97 }
98 else
99 {
100
101 /* Check for interrupt call. */
102 if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
103 {
104
105 /* Now, make sure the call is from an interrupt and not initialization. */
106 if (TX_THREAD_GET_SYSTEM_STATE() < TX_INITIALIZE_IN_PROGRESS)
107 {
108
109 /* Invalid caller of this function, return appropriate error code. */
110 status = TX_CALLER_ERROR;
111 }
112 }
113 }
114
115 /* Determine if everything is okay. */
116 if (status == TX_SUCCESS)
117 {
118
119 /* Call actual put mutex function. */
120 status = _tx_mutex_put(mutex_ptr);
121 }
122
123 /* Return completion status. */
124 return(status);
125 }
126
127