using System; using System.Runtime.InteropServices; using Vanara.Extensions; namespace Vanara.PInvoke { public static partial class Kernel32 { /// /// Initializes the head of a singly linked list. /// /// /// /// A pointer to an SLIST_HEADER structure that represents the head of a singly linked list. This structure is for system use only. /// /// /// /// This function does not return a value. /// /// /// /// All list items must be aligned on a MEMORY_ALLOCATION_ALIGNMENT boundary. Unaligned items can cause unpredictable results. /// See _aligned_malloc. /// /// /// To add items to the list, use the InterlockedPushEntrySList function. To remove items from the list, use the /// InterlockedPopEntrySList function. /// /// Examples /// For an example, see Using Singly Linked Lists. /// // https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-initializeslisthead void // InitializeSListHead( PSLIST_HEADER ListHead ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("interlockedapi.h", MSDNShortId = "4e34f947-1687-4ea9-aaa1-8d8dc11dad70")] public static extern void InitializeSListHead(out SLIST_HEADER ListHead); /// /// Removes all items from a singly linked list. Access to the list is synchronized on a multiprocessor system. /// /// /// /// Pointer to an SLIST_HEADER structure that represents the head of the singly linked list. This structure is for system use only. /// /// /// /// The return value is a pointer to the items removed from the list. If the list is empty, the return value is NULL. /// /// /// /// All list items must be aligned on a MEMORY_ALLOCATION_ALIGNMENT boundary; otherwise, this function will behave /// unpredictably. See _aligned_malloc. /// /// Examples /// For an example, see Using Singly Linked Lists. /// // https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-interlockedflushslist PSLIST_ENTRY // InterlockedFlushSList( PSLIST_HEADER ListHead ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("interlockedapi.h", MSDNShortId = "3fde3377-8a98-4976-a350-2c173b209e8c")] public static extern IntPtr InterlockedFlushSList(in SLIST_HEADER ListHead); /// /// Removes an item from the front of a singly linked list. Access to the list is synchronized on a multiprocessor system. /// /// /// Pointer to an SLIST_HEADER structure that represents the head of a singly linked list. /// /// /// The return value is a pointer to the item removed from the list. If the list is empty, the return value is NULL. /// /// /// /// All list items must be aligned on a MEMORY_ALLOCATION_ALIGNMENT boundary; otherwise, this function will behave /// unpredictably. See _aligned_malloc. /// /// Examples /// For an example, see Using Singly Linked Lists. /// // https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-interlockedpopentryslist PSLIST_ENTRY // InterlockedPopEntrySList( PSLIST_HEADER ListHead ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("interlockedapi.h", MSDNShortId = "10760fd4-5973-4ab0-991c-7a5951c798a4")] public static extern IntPtr InterlockedPopEntrySList(in SLIST_HEADER ListHead); /// /// Inserts an item at the front of a singly linked list. Access to the list is synchronized on a multiprocessor system. /// /// /// Pointer to an SLIST_HEADER structure that represents the head of a singly linked list. /// /// /// Pointer to an SLIST_ENTRY structure that represents an item in a singly linked list. /// /// /// The return value is the previous first item in the list. If the list was previously empty, the return value is NULL. /// /// /// /// All list items must be aligned on a MEMORY_ALLOCATION_ALIGNMENT boundary; otherwise, this function will behave /// unpredictably. See _aligned_malloc. /// /// Examples /// For an example, see Using Singly Linked Lists. /// // https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-interlockedpushentryslist PSLIST_ENTRY // InterlockedPushEntrySList( PSLIST_HEADER ListHead, __drv_aliasesMem PSLIST_ENTRY ListEntry ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("interlockedapi.h", MSDNShortId = "60e3b6f7-f556-4699-be90-db7330cfb8ca")] public static extern IntPtr InterlockedPushEntrySList(in SLIST_HEADER ListHead, IntPtr ListEntry); /// /// Inserts a singly-linked list at the front of another singly linked list. Access to the lists is synchronized on a multiprocessor system. /// /// /// Pointer to an SLIST_HEADER structure that represents the head of a singly linked list. The list specified by the List and /// ListEnd parameters is inserted at the front of this list. /// /// Pointer to an SLIST_ENTRY structure that represents the first item in the list to be inserted. /// Pointer to an SLIST_ENTRY structure that represents the last item in the list to be inserted. /// The number of items in the list to be inserted. /// /// The return value is the previous first item in the list specified by the ListHead parameter. If the list was previously empty, /// the return value is NULL. /// // PSLIST_ENTRY FASTCALL InterlockedPushListSList( _Inout_ PSLIST_HEADER ListHead, _Inout_ PSLIST_ENTRY List, _Inout_ PSLIST_ENTRY // ListEnd, _In_ ULONG Count); https://msdn.microsoft.com/en-us/library/windows/desktop/hh448545(v=vs.85).aspx [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("WinBase.h", MSDNShortId = "hh448545")] public static extern IntPtr InterlockedPushListSList(in SLIST_HEADER ListHead, IntPtr List, IntPtr ListEnd, uint Count); /// /// /// Inserts a singly-linked list at the front of another singly linked list. Access to the lists is synchronized on a multiprocessor /// system. This version of the method does not use the __fastcall calling convention. /// /// /// /// /// Pointer to an SLIST_HEADER structure that represents the head of a singly linked list. The list specified by the List and /// ListEnd parameters is inserted at the front of this list. /// /// /// /// Pointer to an SLIST_ENTRY structure that represents the first item in the list to be inserted. /// /// /// Pointer to an SLIST_ENTRY structure that represents the last item in the list to be inserted. /// /// /// The number of items in the list to be inserted. /// /// /// /// The return value is the previous first item in the list specified by the ListHead parameter. If the list was previously empty, /// the return value is NULL. /// /// /// /// /// All list items must be aligned on a MEMORY_ALLOCATION_ALIGNMENT boundary; otherwise, this function will behave /// unpredictably. See _aligned_malloc. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-interlockedpushlistslistex PSLIST_ENTRY // InterlockedPushListSListEx( PSLIST_HEADER ListHead, PSLIST_ENTRY List, PSLIST_ENTRY ListEnd, ULONG Count ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("interlockedapi.h", MSDNShortId = "f4f334c6-fda8-4c5f-9177-b672c8aed6b3")] public static extern IntPtr InterlockedPushListSListEx(in SLIST_HEADER ListHead, IntPtr List, IntPtr ListEnd, uint Count); /// /// Retrieves the number of entries in the specified singly linked list. /// /// /// /// A pointer to an SLIST_HEADER structure that represents the head of a singly linked list. This structure is for system use only. /// /// The list must be previously initialized with the InitializeSListHead function. /// /// /// The function returns the number of entries in the list, up to a maximum value of 65535. /// /// /// /// The system does not limit the number of entries in a singly linked list. However, the return value of QueryDepthSList is /// truncated to 16 bits, so the maximum value it can return is 65535. If the specified singly linked list contains more than 65535 /// entries, QueryDepthSList returns the number of entries in the list modulo 65535. For example, if the specified list /// contains 65536 entries, QueryDepthSList returns zero. /// /// /// The return value of QueryDepthSList should not be relied upon in multithreaded applications because the item count can be /// changed at any time by another thread. /// /// // https://docs.microsoft.com/en-us/windows/desktop/api/interlockedapi/nf-interlockedapi-querydepthslist USHORT QueryDepthSList( // PSLIST_HEADER ListHead ); [DllImport(Lib.Kernel32, SetLastError = false, ExactSpelling = true)] [PInvokeData("interlockedapi.h", MSDNShortId = "3f9b4481-647f-457f-bdfb-62e6ae4198e5")] public static extern ushort QueryDepthSList(in SLIST_HEADER ListHead); /// An SLIST_ENTRY structure describes an entry in a sequenced singly linked list. // typedef struct _SLIST_ENTRY { struct _SLIST_ENTRY *Next;} SLIST_ENTRY, *PSLIST_ENTRY; https://msdn.microsoft.com/en-us/library/windows/hardware/ff563805(v=vs.85).aspx [PInvokeData("winnt.h")] [StructLayout(LayoutKind.Sequential, Size = 16)] public struct SLIST_ENTRY { /// Pointer to the next entry in the list, or NULL if there is no next entry in the list. public IntPtr Next; /// The next entry in the list, or if there is no next entry in the list. public SLIST_ENTRY? NextEntry => Next.ToNullableStructure(); } /// /// /// An SLIST_HEADER structure is an opaque structure that serves as the header for a sequenced singly linked list. For more /// information, see Singly and Doubly Linked Lists. /// /// On 64-bit platforms, SLIST_HEADER structures must be 16-byte aligned. /// [PInvokeData("winnt.h")] [StructLayout(LayoutKind.Sequential, Size = 16)] public struct SLIST_HEADER { /// public ulong Alignment; /// public ulong Region; } } }