FreeRDP
Loading...
Searching...
No Matches
TestInterlockedDList.c
1
2#include <stdio.h>
3#include <winpr/crt.h>
4#include <winpr/windows.h>
5#include <winpr/interlocked.h>
6
7typedef struct
8{
9 WINPR_LIST_ENTRY ItemEntry;
10 ULONG Signature;
11} LIST_ITEM, *PLIST_ITEM;
12
13int TestInterlockedDList(int argc, char* argv[])
14{
15 ULONG Count = 0;
16 PLIST_ITEM pListItem = NULL;
17 WINPR_PLIST_ENTRY pListHead = NULL;
18 WINPR_PLIST_ENTRY pListEntry = NULL;
19 WINPR_UNUSED(argc);
20 WINPR_UNUSED(argv);
21 pListHead = (WINPR_PLIST_ENTRY)winpr_aligned_malloc(sizeof(WINPR_LIST_ENTRY),
22 MEMORY_ALLOCATION_ALIGNMENT);
23
24 if (!pListHead)
25 {
26 printf("Memory allocation failed.\n");
27 return -1;
28 }
29
30 InitializeListHead(pListHead);
31
32 if (!IsListEmpty(pListHead))
33 {
34 printf("Expected empty list\n");
35 return -1;
36 }
37
38 /* InsertHeadList / RemoveHeadList */
39
40 printf("InsertHeadList / RemoveHeadList\n");
41
42 for (Count = 1; Count <= 10; Count += 1)
43 {
44 pListItem =
45 (PLIST_ITEM)winpr_aligned_malloc(sizeof(LIST_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
46 pListItem->Signature = Count;
47 InsertHeadList(pListHead, &(pListItem->ItemEntry));
48 }
49
50 for (Count = 10; Count >= 1; Count -= 1)
51 {
52 pListEntry = RemoveHeadList(pListHead);
53 pListItem = (PLIST_ITEM)pListEntry;
54 winpr_aligned_free(pListItem);
55 }
56
57 /* InsertTailList / RemoveTailList */
58
59 printf("InsertTailList / RemoveTailList\n");
60
61 for (Count = 1; Count <= 10; Count += 1)
62 {
63 pListItem =
64 (PLIST_ITEM)winpr_aligned_malloc(sizeof(LIST_ITEM), MEMORY_ALLOCATION_ALIGNMENT);
65 pListItem->Signature = Count;
66 InsertTailList(pListHead, &(pListItem->ItemEntry));
67 }
68
69 for (Count = 10; Count >= 1; Count -= 1)
70 {
71 pListEntry = RemoveTailList(pListHead);
72 pListItem = (PLIST_ITEM)pListEntry;
73 winpr_aligned_free(pListItem);
74 }
75
76 winpr_aligned_free(pListHead);
77
78 return 0;
79}