Sync with trunk (48237)
[reactos.git] / ntoskrnl / ex / amd64 / fastinterlck.c
1 /*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/ex/fastinterlck.c
5 * PURPOSE: Portable Ex*Interlocked and REGISTER routines for amd64
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 * Timo Kreuzer
8 */
9
10 /* INCLUDES *******************************************************************/
11
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15
16 #undef ExInterlockedAddLargeInteger
17 #undef ExInterlockedAddUlong
18 #undef ExInterlockedExtendZone
19 #undef ExInterlockedInsertHeadList
20 #undef ExInterlockedInsertTailList
21 #undef ExInterlockedPopEntryList
22 #undef ExInterlockedPushEntryList
23 #undef ExInterlockedRemoveHeadList
24 #undef ExpInterlockedFlushSList
25 #undef ExpInterlockedPopEntrySList
26 #undef ExpInterlockedPushEntrySList
27
28 /* FUNCTIONS ******************************************************************/
29
30 LARGE_INTEGER
31 ExInterlockedAddLargeInteger(IN PLARGE_INTEGER Addend,
32 IN LARGE_INTEGER Increment,
33 IN PKSPIN_LOCK Lock)
34 {
35 LARGE_INTEGER Int;
36 Int.QuadPart = _InterlockedExchangeAdd64(&Addend->QuadPart,
37 Increment.QuadPart);
38 return Int;
39 }
40
41 ULONG
42 ExInterlockedAddUlong(IN PULONG Addend,
43 IN ULONG Increment,
44 PKSPIN_LOCK Lock)
45 {
46 return (ULONG)_InterlockedExchangeAdd((PLONG)Addend, Increment);
47 }
48
49 PLIST_ENTRY
50 ExInterlockedInsertHeadList(IN PLIST_ENTRY ListHead,
51 IN PLIST_ENTRY ListEntry,
52 IN PKSPIN_LOCK Lock)
53 {
54 KIRQL OldIrql;
55 PLIST_ENTRY OldHead = NULL;
56 KeAcquireSpinLock(Lock, &OldIrql);
57 if (!IsListEmpty(ListHead)) OldHead = ListEntry->Flink;
58 InsertHeadList(ListHead, ListEntry);
59 KeReleaseSpinLock(Lock, OldIrql);
60 return OldHead;
61 }
62
63 PLIST_ENTRY
64 ExInterlockedInsertTailList(IN PLIST_ENTRY ListHead,
65 IN PLIST_ENTRY ListEntry,
66 IN PKSPIN_LOCK Lock)
67 {
68 KIRQL OldIrql;
69 PLIST_ENTRY OldHead = NULL;
70 KeAcquireSpinLock(Lock, &OldIrql);
71 if (!IsListEmpty(ListHead)) OldHead = ListEntry->Blink;
72 InsertTailList(ListHead, ListEntry);
73 KeReleaseSpinLock(Lock, OldIrql);
74 return OldHead;
75 }
76
77 PSINGLE_LIST_ENTRY
78 ExInterlockedPopEntryList(IN PSINGLE_LIST_ENTRY ListHead,
79 IN PKSPIN_LOCK Lock)
80 {
81 KIRQL OldIrql;
82 PSINGLE_LIST_ENTRY FirstEntry;
83 KeAcquireSpinLock(Lock, &OldIrql);
84 FirstEntry = PopEntryList(ListHead);
85 KeReleaseSpinLock(Lock, OldIrql);
86 return FirstEntry;
87 }
88
89 PSINGLE_LIST_ENTRY
90 ExInterlockedPushEntryList(IN PSINGLE_LIST_ENTRY ListHead,
91 IN PSINGLE_LIST_ENTRY ListEntry,
92 IN PKSPIN_LOCK Lock)
93 {
94 KIRQL OldIrql;
95 PSINGLE_LIST_ENTRY OldHead = NULL;
96 KeAcquireSpinLock(Lock, &OldIrql);
97 OldHead = ListHead->Next;
98 PushEntryList(ListHead, ListEntry);
99 KeReleaseSpinLock(Lock, OldIrql);
100 return OldHead;
101 }
102
103 PLIST_ENTRY
104 ExInterlockedRemoveHeadList(IN PLIST_ENTRY ListHead,
105 IN PKSPIN_LOCK Lock)
106 {
107 KIRQL OldIrql;
108 PLIST_ENTRY OldHead = NULL;
109 KeAcquireSpinLock(Lock, &OldIrql);
110 if (!IsListEmpty(ListHead)) OldHead = RemoveHeadList(ListHead);
111 KeReleaseSpinLock(Lock, OldIrql);
112 return OldHead;
113 }
114