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_semaphore.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _txe_semaphore_info_get                             PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    William E. Lamie, Microsoft Corporation                             */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function checks for errors in the semaphore information get    */
45 /*    service.                                                            */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    semaphore_ptr                     Pointer to semaphore control block*/
50 /*    name                              Destination for the semaphore name*/
51 /*    current_value                     Destination for current value of  */
52 /*                                        the semaphore                   */
53 /*    first_suspended                   Destination for pointer of first  */
54 /*                                        thread suspended on semaphore   */
55 /*    suspended_count                   Destination for suspended count   */
56 /*    next_semaphore                    Destination for pointer to next   */
57 /*                                        semaphore on the created list   */
58 /*                                                                        */
59 /*  OUTPUT                                                                */
60 /*                                                                        */
61 /*    TX_SEMAPHORE_ERROR                Invalid semaphore pointer         */
62 /*    status                            Completion status                 */
63 /*                                                                        */
64 /*  CALLS                                                                 */
65 /*                                                                        */
66 /*    _tx_semaphore_info_get            Actual semaphore info get service */
67 /*                                                                        */
68 /*  CALLED BY                                                             */
69 /*                                                                        */
70 /*    Application Code                                                    */
71 /*                                                                        */
72 /*  RELEASE HISTORY                                                       */
73 /*                                                                        */
74 /*    DATE              NAME                      DESCRIPTION             */
75 /*                                                                        */
76 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
77 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
78 /*                                            resulting in version 6.1    */
79 /*                                                                        */
80 /**************************************************************************/
_txe_semaphore_info_get(TX_SEMAPHORE * semaphore_ptr,CHAR ** name,ULONG * current_value,TX_THREAD ** first_suspended,ULONG * suspended_count,TX_SEMAPHORE ** next_semaphore)81 UINT  _txe_semaphore_info_get(TX_SEMAPHORE *semaphore_ptr, CHAR **name, ULONG *current_value,
82                     TX_THREAD **first_suspended, ULONG *suspended_count,
83                     TX_SEMAPHORE **next_semaphore)
84 {
85 
86 UINT        status;
87 
88 
89     /* Check for an invalid semaphore pointer.  */
90     if (semaphore_ptr == TX_NULL)
91     {
92 
93         /* Semaphore pointer is invalid, return appropriate error code.  */
94         status =  TX_SEMAPHORE_ERROR;
95     }
96 
97     /* Now check for a valid semaphore ID.  */
98     else if (semaphore_ptr -> tx_semaphore_id != TX_SEMAPHORE_ID)
99     {
100 
101         /* Semaphore pointer is invalid, return appropriate error code.  */
102         status =  TX_SEMAPHORE_ERROR;
103     }
104     else
105     {
106 
107         /* Otherwise, call the actual semaphore information get service.  */
108         status =  _tx_semaphore_info_get(semaphore_ptr, name, current_value, first_suspended,
109                                                                 suspended_count, next_semaphore);
110     }
111 
112     /* Return completion status.  */
113     return(status);
114 }
115 
116