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