fe96ab6248db91058aebbe007d16a04b3fcad3b2
[reactos.git] / reactos / lib / rtl / slist.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Runtime Library
4 * PURPOSE: Slist Routines
5 * FILE: lib/rtl/slist.c
6 * PROGRAMERS: Stefan Ginsberg (stefan__100__@hotmail.com)
7 */
8
9 /* INCLUDES *****************************************************************/
10
11 #include <rtl.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16 /* FUNCTIONS ***************************************************************/
17
18 VOID
19 NTAPI
20 RtlInitializeSListHead(IN PSLIST_HEADER ListHead)
21 {
22 #ifdef _WIN64
23 ListHead->Alignment = 0;
24 ListHead->Region = 0;
25 ListHead->Header8.Init = 1;
26 // ListHead->Header8.HeaderType = 1; // FIXME: depending on cmpxchg16b support?
27 #else
28 ListHead->Alignment = 0;
29 #endif
30 }
31
32 PSLIST_ENTRY
33 NTAPI
34 RtlFirstEntrySList(IN const SLIST_HEADER *ListHead)
35 {
36 #ifdef _WIN64
37 if (ListHead->Header8.HeaderType)
38 {
39 return (PVOID)(ListHead->Region & ~0xF);
40 }
41 else
42 {
43 union {
44 PVOID P;
45 struct {
46 ULONG64 Reserved:4;
47 ULONG64 NextEntry:39;
48 ULONG64 Reserved2:21;
49 } Bits;
50 } Pointer;
51
52 Pointer.P = (PVOID)ListHead;
53 Pointer.Bits.NextEntry = ListHead->Header8.NextEntry;
54 return Pointer.P;
55 }
56 #else
57 return ListHead->Next.Next;
58 #endif
59 }
60
61 WORD
62 NTAPI
63 RtlQueryDepthSList(IN PSLIST_HEADER ListHead)
64 {
65 #ifdef _WIN64
66 return ListHead->Header8.HeaderType ?
67 (WORD)ListHead->Header16.Sequence : (WORD)ListHead->Header8.Sequence;
68 #else
69 return ListHead->Depth;
70 #endif
71 }