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 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    tx_semaphore.h                                      PORTABLE C      */
29 /*                                                           6.1          */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    William E. Lamie, Microsoft Corporation                             */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file defines the ThreadX semaphore management component,       */
37 /*    including all data types and external references.  It is assumed    */
38 /*    that tx_api.h and tx_port.h have already been included.             */
39 /*                                                                        */
40 /*  RELEASE HISTORY                                                       */
41 /*                                                                        */
42 /*    DATE              NAME                      DESCRIPTION             */
43 /*                                                                        */
44 /*  05-19-2020     William E. Lamie         Initial Version 6.0           */
45 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
46 /*                                            resulting in version 6.1    */
47 /*                                                                        */
48 /**************************************************************************/
49 
50 #ifndef TX_SEMAPHORE_H
51 #define TX_SEMAPHORE_H
52 
53 
54 /* Define semaphore control specific data definitions.  */
55 
56 #define TX_SEMAPHORE_ID                         ((ULONG) 0x53454D41)
57 
58 
59 /* Determine if in-line component initialization is supported by the
60    caller.  */
61 #ifdef TX_INVOKE_INLINE_INITIALIZATION
62             /* Yes, in-line initialization is supported, remap the
63                semaphore initialization function.  */
64 #ifndef TX_SEMAPHORE_ENABLE_PERFORMANCE_INFO
65 #define _tx_semaphore_initialize() \
66                     _tx_semaphore_created_ptr =                   TX_NULL;     \
67                     _tx_semaphore_created_count =                 TX_EMPTY
68 #else
69 #define _tx_semaphore_initialize() \
70                     _tx_semaphore_created_ptr =                   TX_NULL;     \
71                     _tx_semaphore_created_count =                 TX_EMPTY;    \
72                     _tx_semaphore_performance_put_count =         ((ULONG) 0); \
73                     _tx_semaphore_performance_get_count =         ((ULONG) 0); \
74                     _tx_semaphore_performance_suspension_count =  ((ULONG) 0); \
75                     _tx_semaphore_performance_timeout_count =     ((ULONG) 0)
76 #endif
77 #define TX_SEMAPHORE_INIT
78 #else
79             /* No in-line initialization is supported, use standard
80                function call.  */
81 VOID        _tx_semaphore_initialize(VOID);
82 #endif
83 
84 
85 /* Define internal semaphore management function prototypes.  */
86 
87 VOID        _tx_semaphore_cleanup(TX_THREAD *thread_ptr, ULONG suspension_sequence);
88 
89 
90 /* Semaphore management component data declarations follow.  */
91 
92 /* Determine if the initialization function of this component is including
93    this file.  If so, make the data definitions really happen.  Otherwise,
94    make them extern so other functions in the component can access them.  */
95 
96 #ifdef TX_SEMAPHORE_INIT
97 #define SEMAPHORE_DECLARE
98 #else
99 #define SEMAPHORE_DECLARE extern
100 #endif
101 
102 
103 /* Define the head pointer of the created semaphore list.  */
104 
105 SEMAPHORE_DECLARE  TX_SEMAPHORE *   _tx_semaphore_created_ptr;
106 
107 
108 /* Define the variable that holds the number of created semaphores. */
109 
110 SEMAPHORE_DECLARE  ULONG            _tx_semaphore_created_count;
111 
112 
113 #ifdef TX_SEMAPHORE_ENABLE_PERFORMANCE_INFO
114 
115 /* Define the total number of semaphore puts.  */
116 
117 SEMAPHORE_DECLARE  ULONG            _tx_semaphore_performance_put_count;
118 
119 
120 /* Define the total number of semaphore gets.  */
121 
122 SEMAPHORE_DECLARE  ULONG            _tx_semaphore_performance_get_count;
123 
124 
125 /* Define the total number of semaphore suspensions.  */
126 
127 SEMAPHORE_DECLARE  ULONG            _tx_semaphore_performance_suspension_count;
128 
129 
130 /* Define the total number of semaphore timeouts.  */
131 
132 SEMAPHORE_DECLARE  ULONG            _tx_semaphore_performance_timeout_count;
133 
134 
135 #endif
136 
137 
138 /* Define default post semaphore delete macro to whitespace, if it hasn't been defined previously (typically in tx_port.h).  */
139 
140 #ifndef TX_SEMAPHORE_DELETE_PORT_COMPLETION
141 #define TX_SEMAPHORE_DELETE_PORT_COMPLETION(s)
142 #endif
143 
144 
145 #endif
146 
147