2012-10-07 04:19:03 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/windows.h>
|
|
|
|
#include <winpr/interlocked.h>
|
|
|
|
|
|
|
|
typedef struct _LIST_ITEM
|
|
|
|
{
|
2016-08-10 11:46:01 +03:00
|
|
|
WINPR_LIST_ENTRY ItemEntry;
|
2012-10-07 04:19:03 +04:00
|
|
|
ULONG Signature;
|
|
|
|
} LIST_ITEM, *PLIST_ITEM;
|
|
|
|
|
|
|
|
int TestInterlockedDList(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
ULONG Count;
|
|
|
|
PLIST_ITEM pListItem;
|
2016-08-10 11:46:01 +03:00
|
|
|
WINPR_PLIST_ENTRY pListHead;
|
|
|
|
WINPR_PLIST_ENTRY pListEntry;
|
2012-10-07 04:19:03 +04:00
|
|
|
|
2016-08-10 11:46:01 +03:00
|
|
|
pListHead = (WINPR_PLIST_ENTRY) _aligned_malloc(sizeof(WINPR_LIST_ENTRY), MEMORY_ALLOCATION_ALIGNMENT);
|
2012-10-07 04:19:03 +04:00
|
|
|
|
|
|
|
if (!pListHead)
|
|
|
|
{
|
|
|
|
printf("Memory allocation failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
InitializeListHead(pListHead);
|
|
|
|
|
|
|
|
if (!IsListEmpty(pListHead))
|
|
|
|
{
|
|
|
|
printf("Expected empty list\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* InsertHeadList / RemoveHeadList */
|
|
|
|
|
|
|
|
printf("InsertHeadList / RemoveHeadList\n");
|
|
|
|
|
|
|
|
for (Count = 1; Count <= 10; Count += 1)
|
|
|
|
{
|
|
|
|
pListItem = (PLIST_ITEM) _aligned_malloc(sizeof(LIST_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
|
|
|
|
pListItem->Signature = Count;
|
|
|
|
InsertHeadList(pListHead, &(pListItem->ItemEntry));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Count = 10; Count >= 1; Count -= 1)
|
|
|
|
{
|
|
|
|
pListEntry = RemoveHeadList(pListHead);
|
|
|
|
pListItem = (PLIST_ITEM) pListEntry;
|
2017-03-28 17:18:00 +03:00
|
|
|
_aligned_free(pListItem);
|
2012-10-07 04:19:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* InsertTailList / RemoveTailList */
|
|
|
|
|
|
|
|
printf("InsertTailList / RemoveTailList\n");
|
|
|
|
|
|
|
|
for (Count = 1; Count <= 10; Count += 1)
|
|
|
|
{
|
|
|
|
pListItem = (PLIST_ITEM) _aligned_malloc(sizeof(LIST_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
|
|
|
|
pListItem->Signature = Count;
|
|
|
|
InsertTailList(pListHead, &(pListItem->ItemEntry));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Count = 10; Count >= 1; Count -= 1)
|
|
|
|
{
|
|
|
|
pListEntry = RemoveTailList(pListHead);
|
|
|
|
pListItem = (PLIST_ITEM) pListEntry;
|
2017-03-28 17:18:00 +03:00
|
|
|
_aligned_free(pListItem);
|
2012-10-07 04:19:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
_aligned_free(pListHead);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|