FreeRDP
interlocked.h
1 
20 #ifndef WINPR_INTERLOCKED_H
21 #define WINPR_INTERLOCKED_H
22 
23 #include <winpr/spec.h>
24 #include <winpr/platform.h>
25 #include <winpr/winpr.h>
26 #include <winpr/wtypes.h>
27 #include <winpr/platform.h>
28 
29 #ifdef __cplusplus
30 extern "C"
31 {
32 #endif
33 
34 #ifndef _WIN32
35 
36 #ifndef CONTAINING_RECORD
37 #define CONTAINING_RECORD(address, type, field) \
38  ((type*)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type*)0)->field))))
39 #endif
40 
41  typedef struct S_WINPR_LIST_ENTRY WINPR_LIST_ENTRY;
42  typedef struct S_WINPR_LIST_ENTRY* WINPR_PLIST_ENTRY;
43 
45  {
46  WINPR_PLIST_ENTRY Flink;
47  WINPR_PLIST_ENTRY Blink;
48  };
49 
50  typedef struct S_WINPR_SINGLE_LIST_ENTRY WINPR_SINGLE_LIST_ENTRY;
51  typedef struct S_WINPR_SINGLE_LIST_ENTRY* WINPR_PSINGLE_LIST_ENTRY;
52 
54  {
55  WINPR_PSINGLE_LIST_ENTRY Next;
56  };
57 
58  typedef struct WINPR_LIST_ENTRY32
59  {
60  DWORD Flink;
61  DWORD Blink;
64 
65  typedef struct WINPR_LIST_ENTRY64
66  {
67  ULONGLONG Flink;
68  ULONGLONG Blink;
71 
72 #ifdef _WIN64
73 
74  typedef struct S_WINPR_SLIST_ENTRY* WINPR_PSLIST_ENTRY;
75  typedef struct DECLSPEC_ALIGN(16) S_WINPR_SLIST_ENTRY
76  {
77  WINPR_PSLIST_ENTRY Next;
78  } WINPR_SLIST_ENTRY;
79 
80 #else /* _WIN64 */
81 
82  WINPR_PRAGMA_DIAG_PUSH
83  WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
84 
85 #define WINPR_SLIST_ENTRY WINPR_SINGLE_LIST_ENTRY
86 #define _WINPR_SLIST_ENTRY _WINPR_SINGLE_LIST_ENTRY
87 #define WINPR_PSLIST_ENTRY WINPR_PSINGLE_LIST_ENTRY
88 
89  WINPR_PRAGMA_DIAG_POP
90 
91 #endif /* _WIN64 */
92 
93 #ifdef _WIN64
94 
95  typedef union DECLSPEC_ALIGN(16)
96  {
97  struct
98  {
99  ULONGLONG Alignment;
100  ULONGLONG Region;
101  } DUMMYSTRUCTNAME;
102 
103  struct
104  {
105  ULONGLONG Depth : 16;
106  ULONGLONG Sequence : 9;
107  ULONGLONG NextEntry : 39;
108  ULONGLONG HeaderType : 1;
109  ULONGLONG Init : 1;
110  ULONGLONG Reserved : 59;
111  ULONGLONG Region : 3;
112  } Header8;
113 
114  struct
115  {
116  ULONGLONG Depth : 16;
117  ULONGLONG Sequence : 48;
118  ULONGLONG HeaderType : 1;
119  ULONGLONG Reserved : 3;
120  ULONGLONG NextEntry : 60;
121  } HeaderX64;
123 
124 #else /* _WIN64 */
125 
126  typedef union
127  {
128  ULONGLONG Alignment;
129 
130  struct
131  {
132  WINPR_SLIST_ENTRY Next;
133  WORD Depth;
134  WORD Sequence;
135  } DUMMYSTRUCTNAME;
137 
138 #endif /* _WIN64 */
139 
140  /* Singly-Linked List */
141 
142  WINPR_API VOID InitializeSListHead(WINPR_PSLIST_HEADER ListHead);
143 
144  WINPR_API WINPR_PSLIST_ENTRY InterlockedPushEntrySList(WINPR_PSLIST_HEADER ListHead,
145  WINPR_PSLIST_ENTRY ListEntry);
146  WINPR_API WINPR_PSLIST_ENTRY InterlockedPushListSListEx(WINPR_PSLIST_HEADER ListHead,
147  WINPR_PSLIST_ENTRY List,
148  WINPR_PSLIST_ENTRY ListEnd,
149  ULONG Count);
150  WINPR_API WINPR_PSLIST_ENTRY InterlockedPopEntrySList(WINPR_PSLIST_HEADER ListHead);
151  WINPR_API WINPR_PSLIST_ENTRY InterlockedFlushSList(WINPR_PSLIST_HEADER ListHead);
152 
153  WINPR_API USHORT QueryDepthSList(WINPR_PSLIST_HEADER ListHead);
154 
155  WINPR_API LONG InterlockedIncrement(LONG volatile* Addend);
156  WINPR_API LONG InterlockedDecrement(LONG volatile* Addend);
157 
158  WINPR_API LONG InterlockedExchange(LONG volatile* Target, LONG Value);
159  WINPR_API LONG InterlockedExchangeAdd(LONG volatile* Addend, LONG Value);
160 
161  WINPR_API LONG InterlockedCompareExchange(LONG volatile* Destination, LONG Exchange,
162  LONG Comperand);
163 
164  WINPR_API PVOID InterlockedCompareExchangePointer(PVOID volatile* Destination, PVOID Exchange,
165  PVOID Comperand);
166 
167 #else /* _WIN32 */
168 #define WINPR_LIST_ENTRY LIST_ENTRY
169 #define WINPR_PLIST_ENTRY PLIST_ENTRY
170 
171 #define WINPR_SINGLE_LIST_ENTRY SINGLE_LIST_ENTRY
172 #define WINPR_PSINGLE_LIST_ENTRY PSINGLE_LIST_ENTRY
173 
174 #define WINPR_SLIST_ENTRY SLIST_ENTRY
175 #define WINPR_PSLIST_ENTRY PSLIST_ENTRY
176 
177 #define WINPR_SLIST_HEADER SLIST_HEADER
178 #define WINPR_PSLIST_HEADER PSLIST_HEADER
179 
180 #endif /* _WIN32 */
181 
182 #if (!defined(_WIN32) || \
183  (defined(_WIN32) && (_WIN32_WINNT < 0x0502) && !defined(InterlockedCompareExchange64)))
184 #define WINPR_INTERLOCKED_COMPARE_EXCHANGE64 1
185 #endif
186 
187 #ifdef WINPR_INTERLOCKED_COMPARE_EXCHANGE64
188 
189  WINPR_API LONGLONG InterlockedCompareExchange64(LONGLONG volatile* Destination,
190  LONGLONG Exchange, LONGLONG Comperand);
191 
192 #endif
193 
194  /* Doubly-Linked List */
195 
196  WINPR_API VOID InitializeListHead(WINPR_PLIST_ENTRY ListHead);
197 
198  WINPR_API BOOL IsListEmpty(const WINPR_LIST_ENTRY* ListHead);
199 
200  WINPR_API BOOL RemoveEntryList(WINPR_PLIST_ENTRY Entry);
201 
202  WINPR_API VOID InsertHeadList(WINPR_PLIST_ENTRY ListHead, WINPR_PLIST_ENTRY Entry);
203  WINPR_API WINPR_PLIST_ENTRY RemoveHeadList(WINPR_PLIST_ENTRY ListHead);
204 
205  WINPR_API VOID InsertTailList(WINPR_PLIST_ENTRY ListHead, WINPR_PLIST_ENTRY Entry);
206  WINPR_API WINPR_PLIST_ENTRY RemoveTailList(WINPR_PLIST_ENTRY ListHead);
207  WINPR_API VOID AppendTailList(WINPR_PLIST_ENTRY ListHead, WINPR_PLIST_ENTRY ListToAppend);
208 
209  WINPR_API VOID PushEntryList(WINPR_PSINGLE_LIST_ENTRY ListHead, WINPR_PSINGLE_LIST_ENTRY Entry);
210  WINPR_API WINPR_PSINGLE_LIST_ENTRY PopEntryList(WINPR_PSINGLE_LIST_ENTRY ListHead);
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif /* WINPR_INTERLOCKED_H */
Definition: interlocked.h:45
Definition: interlocked.h:54