20 #ifndef WINPR_INTERLOCKED_H
21 #define WINPR_INTERLOCKED_H
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>
36 #ifndef CONTAINING_RECORD
37 #define CONTAINING_RECORD(address, type, field) \
38 ((type*)(((ULONG_PTR)address) - (ULONG_PTR)(&(((type*)0)->field))))
46 WINPR_PLIST_ENTRY Flink;
47 WINPR_PLIST_ENTRY Blink;
55 WINPR_PSINGLE_LIST_ENTRY Next;
74 typedef struct S_WINPR_SLIST_ENTRY* WINPR_PSLIST_ENTRY;
75 typedef struct DECLSPEC_ALIGN(16) S_WINPR_SLIST_ENTRY
77 WINPR_PSLIST_ENTRY Next;
82 WINPR_PRAGMA_DIAG_PUSH
83 WINPR_PRAGMA_DIAG_IGNORED_RESERVED_ID_MACRO
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
95 typedef union DECLSPEC_ALIGN(16)
105 ULONGLONG Depth : 16;
106 ULONGLONG Sequence : 9;
107 ULONGLONG NextEntry : 39;
108 ULONGLONG HeaderType : 1;
110 ULONGLONG Reserved : 59;
111 ULONGLONG Region : 3;
116 ULONGLONG Depth : 16;
117 ULONGLONG Sequence : 48;
118 ULONGLONG HeaderType : 1;
119 ULONGLONG Reserved : 3;
120 ULONGLONG NextEntry : 60;
132 WINPR_SLIST_ENTRY Next;
145 WINPR_PSLIST_ENTRY ListEntry);
147 WINPR_PSLIST_ENTRY List,
148 WINPR_PSLIST_ENTRY ListEnd,
155 WINPR_API LONG InterlockedIncrement(LONG
volatile* Addend);
156 WINPR_API LONG InterlockedDecrement(LONG
volatile* Addend);
158 WINPR_API LONG InterlockedExchange(LONG
volatile* Target, LONG Value);
159 WINPR_API LONG InterlockedExchangeAdd(LONG
volatile* Addend, LONG Value);
161 WINPR_API LONG InterlockedCompareExchange(LONG
volatile* Destination, LONG Exchange,
164 WINPR_API PVOID InterlockedCompareExchangePointer(PVOID
volatile* Destination, PVOID Exchange,
168 #define WINPR_LIST_ENTRY LIST_ENTRY
169 #define WINPR_PLIST_ENTRY PLIST_ENTRY
171 #define WINPR_SINGLE_LIST_ENTRY SINGLE_LIST_ENTRY
172 #define WINPR_PSINGLE_LIST_ENTRY PSINGLE_LIST_ENTRY
174 #define WINPR_SLIST_ENTRY SLIST_ENTRY
175 #define WINPR_PSLIST_ENTRY PSLIST_ENTRY
177 #define WINPR_SLIST_HEADER SLIST_HEADER
178 #define WINPR_PSLIST_HEADER PSLIST_HEADER
182 #if (!defined(_WIN32) || \
183 (defined(_WIN32) && (_WIN32_WINNT < 0x0502) && !defined(InterlockedCompareExchange64)))
184 #define WINPR_INTERLOCKED_COMPARE_EXCHANGE64 1
187 #ifdef WINPR_INTERLOCKED_COMPARE_EXCHANGE64
189 WINPR_API LONGLONG InterlockedCompareExchange64(LONGLONG
volatile* Destination,
190 LONGLONG Exchange, LONGLONG Comperand);
196 WINPR_API VOID InitializeListHead(WINPR_PLIST_ENTRY ListHead);
198 WINPR_API BOOL IsListEmpty(
const WINPR_LIST_ENTRY* ListHead);
200 WINPR_API BOOL RemoveEntryList(WINPR_PLIST_ENTRY Entry);
202 WINPR_API VOID InsertHeadList(WINPR_PLIST_ENTRY ListHead, WINPR_PLIST_ENTRY Entry);
203 WINPR_API WINPR_PLIST_ENTRY RemoveHeadList(WINPR_PLIST_ENTRY ListHead);
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);
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);