Blame winpr/libwinpr/interlocked/interlocked.c

Packit Service fa4841
/**
Packit Service fa4841
 * WinPR: Windows Portable Runtime
Packit Service fa4841
 * Interlocked Singly-Linked Lists
Packit Service fa4841
 *
Packit Service fa4841
 * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
Packit Service fa4841
 *
Packit Service fa4841
 * Licensed under the Apache License, Version 2.0 (the "License");
Packit Service fa4841
 * you may not use this file except in compliance with the License.
Packit Service fa4841
 * You may obtain a copy of the License at
Packit Service fa4841
 *
Packit Service fa4841
 *     http://www.apache.org/licenses/LICENSE-2.0
Packit Service fa4841
 *
Packit Service fa4841
 * Unless required by applicable law or agreed to in writing, software
Packit Service fa4841
 * distributed under the License is distributed on an "AS IS" BASIS,
Packit Service fa4841
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Packit Service fa4841
 * See the License for the specific language governing permissions and
Packit Service fa4841
 * limitations under the License.
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
#ifdef HAVE_CONFIG_H
Packit Service fa4841
#include "config.h"
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
#include <winpr/synch.h>
Packit Service fa4841
#include <winpr/handle.h>
Packit Service fa4841
Packit Service fa4841
#include <winpr/interlocked.h>
Packit Service fa4841
Packit Service fa4841
/* Singly-Linked List */
Packit Service fa4841
Packit Service fa4841
#ifndef _WIN32
Packit Service fa4841
Packit Service fa4841
#include <stdio.h>
Packit Service fa4841
#include <stdlib.h>
Packit Service fa4841
Packit Service fa4841
VOID InitializeSListHead(WINPR_PSLIST_HEADER ListHead)
Packit Service fa4841
{
Packit Service fa4841
#ifdef _WIN64
Packit Service fa4841
	ListHead->s.Alignment = 0;
Packit Service fa4841
	ListHead->s.Region = 0;
Packit Service fa4841
	ListHead->Header8.Init = 1;
Packit Service fa4841
#else
Packit Service fa4841
	ListHead->Alignment = 0;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
WINPR_PSLIST_ENTRY InterlockedPushEntrySList(WINPR_PSLIST_HEADER ListHead,
Packit Service fa4841
                                             WINPR_PSLIST_ENTRY ListEntry)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_SLIST_HEADER old;
Packit Service fa4841
	WINPR_SLIST_HEADER newHeader;
Packit Service fa4841
Packit Service fa4841
#ifdef _WIN64
Packit Service fa4841
	newHeader.HeaderX64.NextEntry = (((ULONG_PTR)ListEntry) >> 4);
Packit Service fa4841
Packit Service fa4841
	while (1)
Packit Service fa4841
	{
Packit Service fa4841
		old = *ListHead;
Packit Service fa4841
Packit Service fa4841
		ListEntry->Next = (PSLIST_ENTRY)(((ULONG_PTR)old.HeaderX64.NextEntry) << 4);
Packit Service fa4841
Packit Service fa4841
		newHeader.HeaderX64.Depth = old.HeaderX64.Depth + 1;
Packit Service fa4841
		newHeader.HeaderX64.Sequence = old.HeaderX64.Sequence + 1;
Packit Service fa4841
Packit Service fa4841
		if (InterlockedCompareExchange64((LONGLONG*)ListHead, newHeader.s.Alignment,
Packit Service fa4841
		                                 old.s.Alignment))
Packit Service fa4841
		{
Packit Service fa4841
			InterlockedCompareExchange64(&((LONGLONG*)ListHead)[1], newHeader.s.Region,
Packit Service fa4841
			                             old.s.Region);
Packit Service fa4841
			break;
Packit Service fa4841
		}
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return (PSLIST_ENTRY)((ULONG_PTR)old.HeaderX64.NextEntry << 4);
Packit Service fa4841
#else
Packit Service fa4841
	newHeader.s.Next.Next = ListEntry;
Packit Service fa4841
Packit Service fa4841
	do
Packit Service fa4841
	{
Packit Service fa4841
		old = *ListHead;
Packit Service fa4841
		ListEntry->Next = old.s.Next.Next;
Packit Service fa4841
		newHeader.s.Depth = old.s.Depth + 1;
Packit Service fa4841
		newHeader.s.Sequence = old.s.Sequence + 1;
Packit Service fa4841
		if (old.Alignment > INT64_MAX)
Packit Service fa4841
			return NULL;
Packit Service fa4841
		if (newHeader.Alignment > INT64_MAX)
Packit Service fa4841
			return NULL;
Packit Service fa4841
		if (ListHead->Alignment > INT64_MAX)
Packit Service fa4841
			return NULL;
Packit Service fa4841
	} while (InterlockedCompareExchange64((LONGLONG*)&ListHead->Alignment,
Packit Service fa4841
	                                      (LONGLONG)newHeader.Alignment,
Packit Service fa4841
	                                      (LONGLONG)old.Alignment) != (LONGLONG)old.Alignment);
Packit Service fa4841
Packit Service fa4841
	return old.s.Next.Next;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
WINPR_PSLIST_ENTRY InterlockedPushListSListEx(WINPR_PSLIST_HEADER ListHead, WINPR_PSLIST_ENTRY List,
Packit Service fa4841
                                              WINPR_PSLIST_ENTRY ListEnd, ULONG Count)
Packit Service fa4841
{
Packit Service fa4841
#ifdef _WIN64
Packit Service fa4841
Packit Service fa4841
#else
Packit Service fa4841
Packit Service fa4841
#endif
Packit Service fa4841
	return NULL;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
WINPR_PSLIST_ENTRY InterlockedPopEntrySList(WINPR_PSLIST_HEADER ListHead)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_SLIST_HEADER old;
Packit Service fa4841
	WINPR_SLIST_HEADER newHeader;
Packit Service fa4841
	WINPR_PSLIST_ENTRY entry;
Packit Service fa4841
Packit Service fa4841
#ifdef _WIN64
Packit Service fa4841
	while (1)
Packit Service fa4841
	{
Packit Service fa4841
		old = *ListHead;
Packit Service fa4841
Packit Service fa4841
		entry = (PSLIST_ENTRY)(((ULONG_PTR)old.HeaderX64.NextEntry) << 4);
Packit Service fa4841
Packit Service fa4841
		if (!entry)
Packit Service fa4841
			return NULL;
Packit Service fa4841
Packit Service fa4841
		newHeader.HeaderX64.NextEntry = ((ULONG_PTR)entry->Next) >> 4;
Packit Service fa4841
		newHeader.HeaderX64.Depth = old.HeaderX64.Depth - 1;
Packit Service fa4841
		newHeader.HeaderX64.Sequence = old.HeaderX64.Sequence - 1;
Packit Service fa4841
Packit Service fa4841
		if (InterlockedCompareExchange64((LONGLONG*)ListHead, newHeader.s.Alignment,
Packit Service fa4841
		                                 old.s.Alignment))
Packit Service fa4841
		{
Packit Service fa4841
			InterlockedCompareExchange64(&((LONGLONG*)ListHead)[1], newHeader.s.Region,
Packit Service fa4841
			                             old.s.Region);
Packit Service fa4841
			break;
Packit Service fa4841
		}
Packit Service fa4841
	}
Packit Service fa4841
#else
Packit Service fa4841
	do
Packit Service fa4841
	{
Packit Service fa4841
		old = *ListHead;
Packit Service fa4841
Packit Service fa4841
		entry = old.s.Next.Next;
Packit Service fa4841
Packit Service fa4841
		if (!entry)
Packit Service fa4841
			return NULL;
Packit Service fa4841
Packit Service fa4841
		newHeader.s.Next.Next = entry->Next;
Packit Service fa4841
		newHeader.s.Depth = old.s.Depth - 1;
Packit Service fa4841
		newHeader.s.Sequence = old.s.Sequence + 1;
Packit Service fa4841
Packit Service fa4841
		if (old.Alignment > INT64_MAX)
Packit Service fa4841
			return NULL;
Packit Service fa4841
		if (newHeader.Alignment > INT64_MAX)
Packit Service fa4841
			return NULL;
Packit Service fa4841
		if (ListHead->Alignment > INT64_MAX)
Packit Service fa4841
			return NULL;
Packit Service fa4841
	} while (InterlockedCompareExchange64((LONGLONG*)&ListHead->Alignment,
Packit Service fa4841
	                                      (LONGLONG)newHeader.Alignment,
Packit Service fa4841
	                                      (LONGLONG)old.Alignment) != (LONGLONG)old.Alignment);
Packit Service fa4841
#endif
Packit Service fa4841
	return entry;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
WINPR_PSLIST_ENTRY InterlockedFlushSList(WINPR_PSLIST_HEADER ListHead)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_SLIST_HEADER old;
Packit Service fa4841
	WINPR_SLIST_HEADER newHeader;
Packit Service fa4841
Packit Service fa4841
	if (!QueryDepthSList(ListHead))
Packit Service fa4841
		return NULL;
Packit Service fa4841
Packit Service fa4841
#ifdef _WIN64
Packit Service fa4841
	newHeader.s.Alignment = 0;
Packit Service fa4841
	newHeader.s.Region = 0;
Packit Service fa4841
	newHeader.HeaderX64.HeaderType = 1;
Packit Service fa4841
Packit Service fa4841
	while (1)
Packit Service fa4841
	{
Packit Service fa4841
		old = *ListHead;
Packit Service fa4841
		newHeader.HeaderX64.Sequence = old.HeaderX64.Sequence + 1;
Packit Service fa4841
Packit Service fa4841
		if (InterlockedCompareExchange64((LONGLONG*)ListHead, newHeader.s.Alignment,
Packit Service fa4841
		                                 old.s.Alignment))
Packit Service fa4841
		{
Packit Service fa4841
			InterlockedCompareExchange64(&((LONGLONG*)ListHead)[1], newHeader.s.Region,
Packit Service fa4841
			                             old.s.Region);
Packit Service fa4841
			break;
Packit Service fa4841
		}
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return (PSLIST_ENTRY)(((ULONG_PTR)old.HeaderX64.NextEntry) << 4);
Packit Service fa4841
#else
Packit Service fa4841
	newHeader.Alignment = 0;
Packit Service fa4841
Packit Service fa4841
	do
Packit Service fa4841
	{
Packit Service fa4841
		old = *ListHead;
Packit Service fa4841
		newHeader.s.Sequence = old.s.Sequence + 1;
Packit Service fa4841
Packit Service fa4841
		if (old.Alignment > INT64_MAX)
Packit Service fa4841
			return NULL;
Packit Service fa4841
		if (newHeader.Alignment > INT64_MAX)
Packit Service fa4841
			return NULL;
Packit Service fa4841
		if (ListHead->Alignment > INT64_MAX)
Packit Service fa4841
			return NULL;
Packit Service fa4841
	} while (InterlockedCompareExchange64((LONGLONG*)&ListHead->Alignment,
Packit Service fa4841
	                                      (LONGLONG)newHeader.Alignment,
Packit Service fa4841
	                                      (LONGLONG)old.Alignment) != (LONGLONG)old.Alignment);
Packit Service fa4841
Packit Service fa4841
	return old.s.Next.Next;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
USHORT QueryDepthSList(WINPR_PSLIST_HEADER ListHead)
Packit Service fa4841
{
Packit Service fa4841
#ifdef _WIN64
Packit Service fa4841
	return ListHead->HeaderX64.Depth;
Packit Service fa4841
#else
Packit Service fa4841
	return ListHead->s.Depth;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
LONG InterlockedIncrement(LONG volatile* Addend)
Packit Service fa4841
{
Packit Service fa4841
#ifdef __GNUC__
Packit Service fa4841
	return __sync_add_and_fetch(Addend, 1);
Packit Service fa4841
#else
Packit Service fa4841
	return 0;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
LONG InterlockedDecrement(LONG volatile* Addend)
Packit Service fa4841
{
Packit Service fa4841
#ifdef __GNUC__
Packit Service fa4841
	return __sync_sub_and_fetch(Addend, 1);
Packit Service fa4841
#else
Packit Service fa4841
	return 0;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
LONG InterlockedExchange(LONG volatile* Target, LONG Value)
Packit Service fa4841
{
Packit Service fa4841
#ifdef __GNUC__
Packit Service fa4841
	return __sync_val_compare_and_swap(Target, *Target, Value);
Packit Service fa4841
#else
Packit Service fa4841
	return 0;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
LONG InterlockedExchangeAdd(LONG volatile* Addend, LONG Value)
Packit Service fa4841
{
Packit Service fa4841
#ifdef __GNUC__
Packit Service fa4841
	return __sync_fetch_and_add(Addend, Value);
Packit Service fa4841
#else
Packit Service fa4841
	return 0;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
LONG InterlockedCompareExchange(LONG volatile* Destination, LONG Exchange, LONG Comperand)
Packit Service fa4841
{
Packit Service fa4841
#ifdef __GNUC__
Packit Service fa4841
	return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
Packit Service fa4841
#else
Packit Service fa4841
	return 0;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
PVOID InterlockedCompareExchangePointer(PVOID volatile* Destination, PVOID Exchange,
Packit Service fa4841
                                        PVOID Comperand)
Packit Service fa4841
{
Packit Service fa4841
#ifdef __GNUC__
Packit Service fa4841
	return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
Packit Service fa4841
#else
Packit Service fa4841
	return 0;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
#endif /* _WIN32 */
Packit Service fa4841
Packit Service fa4841
#if defined(_WIN32) && !defined(WINPR_INTERLOCKED_COMPARE_EXCHANGE64)
Packit Service fa4841
Packit Service fa4841
/* InterlockedCompareExchange64 already defined */
Packit Service fa4841
Packit Service fa4841
#elif defined(_WIN32) && defined(WINPR_INTERLOCKED_COMPARE_EXCHANGE64)
Packit Service fa4841
Packit Service fa4841
static volatile HANDLE mutex = NULL;
Packit Service fa4841
Packit Service fa4841
BOOL static_mutex_lock(volatile HANDLE* static_mutex)
Packit Service fa4841
{
Packit Service fa4841
	if (*static_mutex == NULL)
Packit Service fa4841
	{
Packit Service fa4841
		HANDLE handle;
Packit Service fa4841
Packit Service fa4841
		if (!(handle = CreateMutex(NULL, FALSE, NULL)))
Packit Service fa4841
			return FALSE;
Packit Service fa4841
Packit Service fa4841
		if (InterlockedCompareExchangePointer((PVOID*)static_mutex, (PVOID)handle, NULL) != NULL)
Packit Service fa4841
			CloseHandle(handle);
Packit Service fa4841
	}
Packit Service fa4841
Packit Service fa4841
	return (WaitForSingleObject(*static_mutex, INFINITE) == WAIT_OBJECT_0);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
LONGLONG InterlockedCompareExchange64(LONGLONG volatile* Destination, LONGLONG Exchange,
Packit Service fa4841
                                      LONGLONG Comperand)
Packit Service fa4841
{
Packit Service fa4841
	LONGLONG previousValue = 0;
Packit Service fa4841
	BOOL locked = static_mutex_lock(&mutex);
Packit Service fa4841
Packit Service fa4841
	previousValue = *Destination;
Packit Service fa4841
Packit Service fa4841
	if (*Destination == Comperand)
Packit Service fa4841
		*Destination = Exchange;
Packit Service fa4841
Packit Service fa4841
	if (locked)
Packit Service fa4841
		ReleaseMutex(mutex);
Packit Service fa4841
	else
Packit Service fa4841
		fprintf(stderr, "WARNING: InterlockedCompareExchange64 operation might have failed\n");
Packit Service fa4841
Packit Service fa4841
	return previousValue;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
#elif (defined(ANDROID) && ANDROID) || \
Packit Service fa4841
    (defined(__GNUC__) && !defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8))
Packit Service fa4841
Packit Service fa4841
#include <pthread.h>
Packit Service fa4841
Packit Service fa4841
static pthread_mutex_t mutex;
Packit Service fa4841
Packit Service fa4841
LONGLONG InterlockedCompareExchange64(LONGLONG volatile* Destination, LONGLONG Exchange,
Packit Service fa4841
                                      LONGLONG Comperand)
Packit Service fa4841
{
Packit Service fa4841
	LONGLONG previousValue = 0;
Packit Service fa4841
Packit Service fa4841
	pthread_mutex_lock(&mutex);
Packit Service fa4841
Packit Service fa4841
	previousValue = *Destination;
Packit Service fa4841
Packit Service fa4841
	if (*Destination == Comperand)
Packit Service fa4841
		*Destination = Exchange;
Packit Service fa4841
Packit Service fa4841
	pthread_mutex_unlock(&mutex);
Packit Service fa4841
Packit Service fa4841
	return previousValue;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
#else
Packit Service fa4841
Packit Service fa4841
LONGLONG InterlockedCompareExchange64(LONGLONG volatile* Destination, LONGLONG Exchange,
Packit Service fa4841
                                      LONGLONG Comperand)
Packit Service fa4841
{
Packit Service fa4841
#ifdef __GNUC__
Packit Service fa4841
	return __sync_val_compare_and_swap(Destination, Comperand, Exchange);
Packit Service fa4841
#else
Packit Service fa4841
	return 0;
Packit Service fa4841
#endif
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
#endif
Packit Service fa4841
Packit Service fa4841
/* Doubly-Linked List */
Packit Service fa4841
Packit Service fa4841
/**
Packit Service fa4841
 * Kernel-Mode Basics: Windows Linked Lists:
Packit Service fa4841
 * http://www.osronline.com/article.cfm?article=499
Packit Service fa4841
 *
Packit Service fa4841
 * Singly and Doubly Linked Lists:
Packit Service fa4841
 * http://msdn.microsoft.com/en-us/library/windows/hardware/ff563802/
Packit Service fa4841
 */
Packit Service fa4841
Packit Service fa4841
VOID InitializeListHead(WINPR_PLIST_ENTRY ListHead)
Packit Service fa4841
{
Packit Service fa4841
	ListHead->Flink = ListHead->Blink = ListHead;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL IsListEmpty(const WINPR_LIST_ENTRY* ListHead)
Packit Service fa4841
{
Packit Service fa4841
	return (BOOL)(ListHead->Flink == ListHead);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
BOOL RemoveEntryList(WINPR_PLIST_ENTRY Entry)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_PLIST_ENTRY OldFlink;
Packit Service fa4841
	WINPR_PLIST_ENTRY OldBlink;
Packit Service fa4841
Packit Service fa4841
	OldFlink = Entry->Flink;
Packit Service fa4841
	OldBlink = Entry->Blink;
Packit Service fa4841
	OldFlink->Blink = OldBlink;
Packit Service fa4841
	OldBlink->Flink = OldFlink;
Packit Service fa4841
Packit Service fa4841
	return (BOOL)(OldFlink == OldBlink);
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
VOID InsertHeadList(WINPR_PLIST_ENTRY ListHead, WINPR_PLIST_ENTRY Entry)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_PLIST_ENTRY OldFlink;
Packit Service fa4841
Packit Service fa4841
	OldFlink = ListHead->Flink;
Packit Service fa4841
	Entry->Flink = OldFlink;
Packit Service fa4841
	Entry->Blink = ListHead;
Packit Service fa4841
	OldFlink->Blink = Entry;
Packit Service fa4841
	ListHead->Flink = Entry;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
WINPR_PLIST_ENTRY RemoveHeadList(WINPR_PLIST_ENTRY ListHead)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_PLIST_ENTRY Flink;
Packit Service fa4841
	WINPR_PLIST_ENTRY Entry;
Packit Service fa4841
Packit Service fa4841
	Entry = ListHead->Flink;
Packit Service fa4841
	Flink = Entry->Flink;
Packit Service fa4841
	ListHead->Flink = Flink;
Packit Service fa4841
	Flink->Blink = ListHead;
Packit Service fa4841
Packit Service fa4841
	return Entry;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
VOID InsertTailList(WINPR_PLIST_ENTRY ListHead, WINPR_PLIST_ENTRY Entry)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_PLIST_ENTRY OldBlink;
Packit Service fa4841
Packit Service fa4841
	OldBlink = ListHead->Blink;
Packit Service fa4841
	Entry->Flink = ListHead;
Packit Service fa4841
	Entry->Blink = OldBlink;
Packit Service fa4841
	OldBlink->Flink = Entry;
Packit Service fa4841
	ListHead->Blink = Entry;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
WINPR_PLIST_ENTRY RemoveTailList(WINPR_PLIST_ENTRY ListHead)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_PLIST_ENTRY Blink;
Packit Service fa4841
	WINPR_PLIST_ENTRY Entry;
Packit Service fa4841
Packit Service fa4841
	Entry = ListHead->Blink;
Packit Service fa4841
	Blink = Entry->Blink;
Packit Service fa4841
	ListHead->Blink = Blink;
Packit Service fa4841
	Blink->Flink = ListHead;
Packit Service fa4841
Packit Service fa4841
	return Entry;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
VOID AppendTailList(WINPR_PLIST_ENTRY ListHead, WINPR_PLIST_ENTRY ListToAppend)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_PLIST_ENTRY ListEnd = ListHead->Blink;
Packit Service fa4841
Packit Service fa4841
	ListHead->Blink->Flink = ListToAppend;
Packit Service fa4841
	ListHead->Blink = ListToAppend->Blink;
Packit Service fa4841
	ListToAppend->Blink->Flink = ListHead;
Packit Service fa4841
	ListToAppend->Blink = ListEnd;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
VOID PushEntryList(WINPR_PSINGLE_LIST_ENTRY ListHead, WINPR_PSINGLE_LIST_ENTRY Entry)
Packit Service fa4841
{
Packit Service fa4841
	Entry->Next = ListHead->Next;
Packit Service fa4841
	ListHead->Next = Entry;
Packit Service fa4841
}
Packit Service fa4841
Packit Service fa4841
WINPR_PSINGLE_LIST_ENTRY PopEntryList(WINPR_PSINGLE_LIST_ENTRY ListHead)
Packit Service fa4841
{
Packit Service fa4841
	WINPR_PSINGLE_LIST_ENTRY FirstEntry;
Packit Service fa4841
Packit Service fa4841
	FirstEntry = ListHead->Next;
Packit Service fa4841
Packit Service fa4841
	if (FirstEntry != NULL)
Packit Service fa4841
		ListHead->Next = FirstEntry->Next;
Packit Service fa4841
Packit Service fa4841
	return FirstEntry;
Packit Service fa4841
}