12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- #ifndef LISTENTRY_H
- #define LISTENTRY_H
- #pragma once
- static __inline void ListEntry_InitNode(PLIST_ENTRY node)
- {
- node->Flink = node->Blink = NULL;
- }
- static __inline void ListEntry_InitHead(PLIST_ENTRY head)
- {
- head->Blink = head;
- head->Flink = head;
- }
- static __inline void ListEntry_DeleteNode(PLIST_ENTRY node)
- {
- PLIST_ENTRY prev = node->Blink;
- PLIST_ENTRY next = node->Flink;
- prev->Flink = next;
- next->Blink = prev;
- node->Flink = node->Blink = NULL;
- }
- static __inline void ListEntry_Insert(PLIST_ENTRY prev, PLIST_ENTRY next, PLIST_ENTRY node)
- {
- prev->Flink = node;
- node->Blink = prev;
- node->Flink = next;
- next->Blink = node;
- }
- static __inline void ListEntry_InsertBefore(PLIST_ENTRY pos, PLIST_ENTRY node)
- {
- ListEntry_Insert(pos->Blink, pos, node);
- }
- static __inline void ListEntry_InsertAfter(PLIST_ENTRY pos, PLIST_ENTRY node)
- {
- ListEntry_Insert(pos, pos->Flink, node);
- }
- static __inline void ListEntry_AddTail(PLIST_ENTRY head, PLIST_ENTRY node)
- {
- ListEntry_Insert(head->Blink, head, node);
- }
- static __inline void ListEntry_AddHead(PLIST_ENTRY head, PLIST_ENTRY node)
- {
- ListEntry_Insert(head, head->Flink, node);
- }
- static __inline PLIST_ENTRY ListEntry_RemoveListHead(PLIST_ENTRY head)
- {
- PLIST_ENTRY t = head->Flink;
- ListEntry_DeleteNode(t);
- return t;
- }
- static __inline PLIST_ENTRY ListEntry_RemoveListTail(PLIST_ENTRY head)
- {
- PLIST_ENTRY t = head->Blink;
- ListEntry_DeleteNode(t);
- return t;
- }
- static __inline int ListEntry_IsEmpty(PLIST_ENTRY head)
- {
- return head->Blink == head;
- }
- static __inline PLIST_ENTRY ListEntry_GetHead(PLIST_ENTRY head)
- {
- return head->Flink;
- }
- static __inline PLIST_ENTRY ListEntry_GetTail(PLIST_ENTRY head)
- {
- return head->Blink;
- }
- #define ListEntry_ForEachSafe(pos, n, head, type, member) \
- for (pos = CONTAINING_RECORD((head)->Flink, type, member), \
- n = CONTAINING_RECORD(pos->member.Flink, type, member); \
- &pos->member != (head); \
- pos = n, n = CONTAINING_RECORD(n->member.Flink, type, member))
- #define ListEntry_ForEach(pos, head, type, member) \
- for (pos = CONTAINING_RECORD((head)->Flink, type, member); \
- &pos->member != head; \
- pos = CONTAINING_RECORD(pos->member.Flink, type, member))
- #endif // LISTENTRY_H
|