1 krisbash 1.1 #ifndef _pal_slist_h
2 #define _pal_slist_h
3
4 #include <stddef.h>
5 #include <string.h>
6 #include "palcommon.h"
7
8 #if !defined(_MSC_VER)
9 # include "atomic.h"
10 #endif
11
12 /*
13 **==============================================================================
14 **
15 ** Windows Version
16 **
17 **==============================================================================
18 */
19
20 #if defined(_MSC_VER)
21
22 krisbash 1.1 PAL_BEGIN_EXTERNC
23
24 #define SList_Alloc( size ) (_aligned_malloc( (size), MEMORY_ALLOCATION_ALIGNMENT ))
25 #define SList_Free( ptr ) (_aligned_free( ptr ))
26
27 typedef struct _SListEntry
28 {
29 /* Private field! */
30 SLIST_ENTRY __private;
31 }
32 SListEntry;
33
34 typedef struct _SListHead
35 {
36 /* Private field! */
37 SLIST_HEADER __private;
38 }
39 SListHead;
40
41 PAL_INLINE void SList_Init(
42 _Out_ SListHead* head)
43 krisbash 1.1 {
44 InitializeSListHead(&head->__private);
45 }
46
47 PAL_INLINE SListEntry* SList_FlushAtomic(
48 _Inout_ SListHead* head)
49 {
50 return (SListEntry*)InterlockedFlushSList(&head->__private);
51 }
52
53 PAL_INLINE SListEntry* SList_PushAtomic(
54 _Inout_ SListHead* head,
55 _Inout_ SListEntry* entry)
56 {
57 return (SListEntry*)InterlockedPushEntrySList(
58 &head->__private,
59 &entry->__private);
60 }
61
62 PAL_INLINE SListEntry* SList_PopAtomic(
63 _Inout_ SListHead* head)
64 krisbash 1.1 {
65 return (SListEntry*)InterlockedPopEntrySList(&head->__private);
66 }
67
68 PAL_INLINE SListEntry* SList_Next(
69 _Inout_ SListEntry* entry)
70 {
71 return (SListEntry*)entry->__private.Next;
72 }
73
74 PAL_END_EXTERNC
75
76 #endif /* defined(_MSC_VER) */
77
78 /*
79 **==============================================================================
80 **
81 ** Non-Windows Version
82 **
83 **==============================================================================
84 */
85 krisbash 1.1
86 #if !defined(_MSC_VER)
87
88 PAL_BEGIN_EXTERNC
89
90 #define SList_Alloc( size ) (PAL_Malloc( size ))
91 #define SList_Free( ptr ) (PAL_Free( ptr ))
92
93 typedef struct ___SListEntryRep
94 {
95 struct _SListEntry* next;
96 }
97 __SListEntryRep;
98
99 typedef struct ___SListHeadRep
100 {
101 struct _SListEntry* next;
102 ptrdiff_t lock;
103 }
104 __SListHeadRep;
105
106 krisbash 1.1 typedef struct _SListEntry
107 {
108 /* Private field! */
109 __SListEntryRep __private;
110 }
111 SListEntry;
112
113 typedef struct _SListHead
114 {
115 /* Private field! */
116 __SListHeadRep __private;
117 }
118 SListHead;
119
120 PAL_INLINE void SList_Init(
121 _Inout_ SListHead* head)
122 {
123 head->__private.next = NULL;
124 head->__private.lock = 0;
125 }
126
127 krisbash 1.1 SListEntry* SList_FlushAtomic(
128 _Inout_ SListHead* head);
129
130 SListEntry* SList_PushAtomic(
131 _Inout_ SListHead* head,
132 _Inout_ SListEntry* entry);
133
134 SListEntry* SList_PopAtomic(
135 _Inout_ SListHead* head);
136
137 PAL_INLINE SListEntry* SList_Next(
138 _Inout_ SListEntry* entry)
139 {
140 return entry->__private.next;
141 }
142
143 PAL_END_EXTERNC
144
145 #endif /* !defined(_MSC_VER) */
146
147 #endif /* _pal_slist_h */
|