Azure IoT common library

Fork of azure_c_shared_utility by Azure IoT

Committer:
Azure.IoT Build
Date:
Fri Apr 08 12:01:36 2016 -0700
Revision:
0:fa2de1b79154
Child:
19:2e0811512ceb
1.0.4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Azure.IoT Build 0:fa2de1b79154 1 // Copyright (c) Microsoft. All rights reserved.
Azure.IoT Build 0:fa2de1b79154 2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
Azure.IoT Build 0:fa2de1b79154 3
Azure.IoT Build 0:fa2de1b79154 4 #include <stdlib.h>
Azure.IoT Build 0:fa2de1b79154 5 #ifdef _CRTDBG_MAP_ALLOC
Azure.IoT Build 0:fa2de1b79154 6 #include <crtdbg.h>
Azure.IoT Build 0:fa2de1b79154 7 #endif
Azure.IoT Build 0:fa2de1b79154 8 #include "azure_c_shared_utility/doublylinkedlist.h"
Azure.IoT Build 0:fa2de1b79154 9
Azure.IoT Build 0:fa2de1b79154 10 void
Azure.IoT Build 0:fa2de1b79154 11 DList_InitializeListHead(
Azure.IoT Build 0:fa2de1b79154 12 PDLIST_ENTRY ListHead
Azure.IoT Build 0:fa2de1b79154 13 )
Azure.IoT Build 0:fa2de1b79154 14 {
Azure.IoT Build 0:fa2de1b79154 15 /* Codes_SRS_DLIST_06_005: [DList_InitializeListHead will initialize the Flink & Blink to the address of the DLIST_ENTRY.] */
Azure.IoT Build 0:fa2de1b79154 16 ListHead->Flink = ListHead->Blink = ListHead;
Azure.IoT Build 0:fa2de1b79154 17 return;
Azure.IoT Build 0:fa2de1b79154 18 }
Azure.IoT Build 0:fa2de1b79154 19
Azure.IoT Build 0:fa2de1b79154 20 int
Azure.IoT Build 0:fa2de1b79154 21 DList_IsListEmpty(
Azure.IoT Build 0:fa2de1b79154 22 const PDLIST_ENTRY ListHead
Azure.IoT Build 0:fa2de1b79154 23 )
Azure.IoT Build 0:fa2de1b79154 24 {
Azure.IoT Build 0:fa2de1b79154 25 /* Codes_SRS_DLIST_06_003: [DList_IsListEmpty shall return a non-zero value if there are no DLIST_ENTRY's on this list other than the list head.] */
Azure.IoT Build 0:fa2de1b79154 26 /* Codes_SRS_DLIST_06_004: [DList_IsListEmpty shall return 0 if there is one or more items in the list.] */
Azure.IoT Build 0:fa2de1b79154 27 return (ListHead->Flink == ListHead);
Azure.IoT Build 0:fa2de1b79154 28 }
Azure.IoT Build 0:fa2de1b79154 29
Azure.IoT Build 0:fa2de1b79154 30 int
Azure.IoT Build 0:fa2de1b79154 31 DList_RemoveEntryList(
Azure.IoT Build 0:fa2de1b79154 32 PDLIST_ENTRY Entry
Azure.IoT Build 0:fa2de1b79154 33 )
Azure.IoT Build 0:fa2de1b79154 34 {
Azure.IoT Build 0:fa2de1b79154 35 /* Codes_SRS_DLIST_06_008: [DList_RemoveEntryList shall remove a listEntry from whatever list it is properly part of.] */
Azure.IoT Build 0:fa2de1b79154 36 /* Codes_SRS_DLIST_06_009: [The remaining list is properly formed.] */
Azure.IoT Build 0:fa2de1b79154 37 /* Codes_SRS_DLIST_06_010: [DList_RemoveEntryList shall return non-zero if the remaining list is empty.] */
Azure.IoT Build 0:fa2de1b79154 38 /* Codes_SRS_DLIST_06_011: [DList_RemoveEntryList shall return zero if the remaining list is NOT empty.] */
Azure.IoT Build 0:fa2de1b79154 39 PDLIST_ENTRY Blink;
Azure.IoT Build 0:fa2de1b79154 40 PDLIST_ENTRY Flink;
Azure.IoT Build 0:fa2de1b79154 41
Azure.IoT Build 0:fa2de1b79154 42 Flink = Entry->Flink;
Azure.IoT Build 0:fa2de1b79154 43 Blink = Entry->Blink;
Azure.IoT Build 0:fa2de1b79154 44 Blink->Flink = Flink;
Azure.IoT Build 0:fa2de1b79154 45 Flink->Blink = Blink;
Azure.IoT Build 0:fa2de1b79154 46 return (Flink == Blink);
Azure.IoT Build 0:fa2de1b79154 47 }
Azure.IoT Build 0:fa2de1b79154 48
Azure.IoT Build 0:fa2de1b79154 49 PDLIST_ENTRY
Azure.IoT Build 0:fa2de1b79154 50 DList_RemoveHeadList(
Azure.IoT Build 0:fa2de1b79154 51 PDLIST_ENTRY ListHead
Azure.IoT Build 0:fa2de1b79154 52 )
Azure.IoT Build 0:fa2de1b79154 53 {
Azure.IoT Build 0:fa2de1b79154 54 /* Codes_SRS_DLIST_06_012: [DList_RemoveHeadList removes the oldest entry from the list defined by the listHead parameter and returns a pointer to that entry.] */
Azure.IoT Build 0:fa2de1b79154 55 /* Codes_SRS_DLIST_06_013: [DList_RemoveHeadList shall return listHead if that's the only item in the list.] */
Azure.IoT Build 0:fa2de1b79154 56
Azure.IoT Build 0:fa2de1b79154 57 PDLIST_ENTRY Flink;
Azure.IoT Build 0:fa2de1b79154 58 PDLIST_ENTRY Entry;
Azure.IoT Build 0:fa2de1b79154 59
Azure.IoT Build 0:fa2de1b79154 60 Entry = ListHead->Flink;
Azure.IoT Build 0:fa2de1b79154 61 Flink = Entry->Flink;
Azure.IoT Build 0:fa2de1b79154 62 ListHead->Flink = Flink;
Azure.IoT Build 0:fa2de1b79154 63 Flink->Blink = ListHead;
Azure.IoT Build 0:fa2de1b79154 64 return Entry;
Azure.IoT Build 0:fa2de1b79154 65 }
Azure.IoT Build 0:fa2de1b79154 66
Azure.IoT Build 0:fa2de1b79154 67
Azure.IoT Build 0:fa2de1b79154 68
Azure.IoT Build 0:fa2de1b79154 69 void
Azure.IoT Build 0:fa2de1b79154 70 DList_InsertTailList(
Azure.IoT Build 0:fa2de1b79154 71 PDLIST_ENTRY ListHead,
Azure.IoT Build 0:fa2de1b79154 72 PDLIST_ENTRY Entry
Azure.IoT Build 0:fa2de1b79154 73 )
Azure.IoT Build 0:fa2de1b79154 74 {
Azure.IoT Build 0:fa2de1b79154 75 PDLIST_ENTRY Blink;
Azure.IoT Build 0:fa2de1b79154 76
Azure.IoT Build 0:fa2de1b79154 77 /* Codes_SRS_DLIST_06_006: [DListInsertTailList shall place the DLIST_ENTRY at the end of the list defined by the listHead parameter.] */
Azure.IoT Build 0:fa2de1b79154 78 Blink = ListHead->Blink;
Azure.IoT Build 0:fa2de1b79154 79 Entry->Flink = ListHead;
Azure.IoT Build 0:fa2de1b79154 80 Entry->Blink = Blink;
Azure.IoT Build 0:fa2de1b79154 81 Blink->Flink = Entry;
Azure.IoT Build 0:fa2de1b79154 82 ListHead->Blink = Entry;
Azure.IoT Build 0:fa2de1b79154 83 return;
Azure.IoT Build 0:fa2de1b79154 84 }
Azure.IoT Build 0:fa2de1b79154 85
Azure.IoT Build 0:fa2de1b79154 86
Azure.IoT Build 0:fa2de1b79154 87 void
Azure.IoT Build 0:fa2de1b79154 88 DList_AppendTailList(
Azure.IoT Build 0:fa2de1b79154 89 PDLIST_ENTRY ListHead,
Azure.IoT Build 0:fa2de1b79154 90 PDLIST_ENTRY ListToAppend
Azure.IoT Build 0:fa2de1b79154 91 )
Azure.IoT Build 0:fa2de1b79154 92 {
Azure.IoT Build 0:fa2de1b79154 93 /* Codes_SRS_DLIST_06_007: [DList_AppendTailList shall place the list defined by listToAppend at the end of the list defined by the listHead parameter.] */
Azure.IoT Build 0:fa2de1b79154 94 PDLIST_ENTRY ListEnd = ListHead->Blink;
Azure.IoT Build 0:fa2de1b79154 95
Azure.IoT Build 0:fa2de1b79154 96 ListHead->Blink->Flink = ListToAppend;
Azure.IoT Build 0:fa2de1b79154 97 ListHead->Blink = ListToAppend->Blink;
Azure.IoT Build 0:fa2de1b79154 98 ListToAppend->Blink->Flink = ListHead;
Azure.IoT Build 0:fa2de1b79154 99 ListToAppend->Blink = ListEnd;
Azure.IoT Build 0:fa2de1b79154 100 return;
Azure.IoT Build 0:fa2de1b79154 101 }
Azure.IoT Build 0:fa2de1b79154 102
Azure.IoT Build 0:fa2de1b79154 103
Azure.IoT Build 0:fa2de1b79154 104 /*Codes_SRS_DLIST_02_002: [DList_InsertHeadList inserts a singular entry in the list having as head listHead after "head".]*/
Azure.IoT Build 0:fa2de1b79154 105 void DList_InsertHeadList(PDLIST_ENTRY listHead, PDLIST_ENTRY entry)
Azure.IoT Build 0:fa2de1b79154 106 {
Azure.IoT Build 0:fa2de1b79154 107 entry->Blink = listHead;
Azure.IoT Build 0:fa2de1b79154 108 entry->Flink = listHead->Flink;
Azure.IoT Build 0:fa2de1b79154 109 listHead->Flink->Blink = entry;
Azure.IoT Build 0:fa2de1b79154 110 listHead->Flink = entry;
Azure.IoT Build 0:fa2de1b79154 111 }