4 #include <winpr/windows.h>
5 #include <winpr/interlocked.h>
11 WINPR_SLIST_ENTRY ItemEntry;
13 } PROGRAM_ITEM, *PPROGRAM_ITEM;
15 int TestInterlockedSList(
int argc,
char* argv[])
28 printf(
"Memory allocation failed.\n");
32 InitializeSListHead(pListHead);
35 for (ULONG Count = 0; Count < ITEM_COUNT; Count++)
37 PPROGRAM_ITEM pProgramItem =
38 (PPROGRAM_ITEM)winpr_aligned_malloc(
sizeof(PROGRAM_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
42 printf(
"Memory allocation failed.\n");
46 pProgramItem->Signature = Count + 1UL;
47 WINPR_PSLIST_ENTRY pFirstEntry =
48 InterlockedPushEntrySList(pListHead, &(pProgramItem->ItemEntry));
49 if (((Count == 0) && pFirstEntry) || ((Count != 0) && !pFirstEntry))
51 printf(
"Error: List is empty.\n");
52 winpr_aligned_free(pProgramItem);
58 for (ULONG Count = 0; Count < ITEM_COUNT; Count++)
60 WINPR_PSLIST_ENTRY pListEntry = InterlockedPopEntrySList(pListHead);
64 printf(
"List is empty.\n");
68 PPROGRAM_ITEM pProgramItem = (PPROGRAM_ITEM)pListEntry;
69 printf(
"Signature is %" PRIu32
"\n", pProgramItem->Signature);
78 winpr_aligned_free(pListEntry);
82 WINPR_PSLIST_ENTRY pFirstEntry = InterlockedPopEntrySList(pListHead);
86 printf(
"Error: List is not empty.\n");
92 winpr_aligned_free(pListHead);