qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tr...@apache.org
Subject [03/50] [abbrv] qpid-dispatch git commit: DISPATCH-228 - Added named DEQ macros for multi-list membership.
Date Fri, 18 Mar 2016 23:06:21 GMT
DISPATCH-228 - Added named DEQ macros for multi-list membership.

Conflicts:
	include/qpid/dispatch/ctools.h


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/c72e179e
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/c72e179e
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/c72e179e

Branch: refs/heads/master
Commit: c72e179ef297d4b94ebda5c025d3eb2f87936bfe
Parents: 1dffeb6
Author: Ted Ross <tross@redhat.com>
Authored: Mon Feb 29 15:54:22 2016 -0500
Committer: Ted Ross <tross@redhat.com>
Committed: Mon Feb 29 15:58:34 2016 -0500

----------------------------------------------------------------------
 include/qpid/dispatch/ctools.h | 128 ++++++++++++++++++++----------------
 tests/tool_test.c              |  56 ++++++++++++++++
 2 files changed, 126 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/c72e179e/include/qpid/dispatch/ctools.h
----------------------------------------------------------------------
diff --git a/include/qpid/dispatch/ctools.h b/include/qpid/dispatch/ctools.h
index 3ac5998..9ab1c70 100644
--- a/include/qpid/dispatch/ctools.h
+++ b/include/qpid/dispatch/ctools.h
@@ -41,134 +41,146 @@
     size_t  size;       \
     } d
 
-#define DEQ_LINKS(t) t *prev; t *next
+#define DEQ_LINKS_N(n,t) t *prev##n; t *next##n
+#define DEQ_LINKS(t) DEQ_LINKS_N(,t)
 #define DEQ_EMPTY {0,0,0,0}
 
 #define DEQ_INIT(d) do { (d).head = 0; (d).tail = 0; (d).scratch = 0; (d).size = 0; } while
(0)
 #define DEQ_IS_EMPTY(d) ((d).head == 0)
-#define DEQ_ITEM_INIT(i) do { (i)->next = 0; (i)->prev = 0; } while(0)
+#define DEQ_ITEM_INIT_N(n,i) do { (i)->next##n = 0; (i)->prev##n = 0; } while(0)
+#define DEQ_ITEM_INIT(i) DEQ_ITEM_INIT_N(,i)
 #define DEQ_HEAD(d) ((d).head)
 #define DEQ_TAIL(d) ((d).tail)
 #define DEQ_SIZE(d) ((d).size)
-#define DEQ_NEXT(i) (i)->next
-#define DEQ_PREV(i) (i)->prev
+#define DEQ_NEXT_N(n,i) (i)->next##n
+#define DEQ_NEXT(i) DEQ_NEXT_N(,i)
+#define DEQ_PREV_N(n,i) (i)->prev##n
+#define DEQ_PREV(i) DEQ_PREV_N(,i)
 #define DEQ_MOVE(d1,d2) do {d2 = d1; DEQ_INIT(d1);} while (0)
 /**
  *@pre ptr points to first element of deq
  *@post ptr points to first element of deq that passes test, or 0. Test should involve ptr.
  */
-#define DEQ_FIND(ptr,test) while((ptr) && !(test)) ptr = DEQ_NEXT(ptr);
+#define DEQ_FIND_N(n,ptr,test) while((ptr) && !(test)) ptr = DEQ_NEXT_N(n,ptr);
+#define DEQ_FIND(ptr,test) DEQ_FIND_N(,ptr,test)
 
-#define DEQ_INSERT_HEAD(d,i)      \
+#define DEQ_INSERT_HEAD_N(n,d,i)  \
 do {                              \
-    CT_ASSERT((i)->next == 0);    \
-    CT_ASSERT((i)->prev == 0);    \
+    CT_ASSERT((i)->next##n == 0); \
+    CT_ASSERT((i)->prev##n == 0); \
     if ((d).head) {               \
-        (i)->next = (d).head;     \
-        (d).head->prev = i;       \
+        (i)->next##n = (d).head;  \
+        (d).head->prev##n = i;    \
     } else {                      \
         (d).tail = i;             \
-        (i)->next = 0;            \
+        (i)->next##n = 0;         \
         CT_ASSERT((d).size == 0); \
     }                             \
-    (i)->prev = 0;                \
+    (i)->prev##n = 0;             \
     (d).head = i;                 \
     (d).size++;                   \
 } while (0)
+#define DEQ_INSERT_HEAD(d,i) DEQ_INSERT_HEAD_N(,d,i)
 
-#define DEQ_INSERT_TAIL(d,i)      \
+#define DEQ_INSERT_TAIL_N(n,d,i)  \
 do {                              \
-    CT_ASSERT((i)->next == 0);    \
-    CT_ASSERT((i)->prev == 0);    \
+    CT_ASSERT((i)->next##n == 0); \
+    CT_ASSERT((i)->prev##n == 0); \
     if ((d).tail) {               \
-        (i)->prev = (d).tail;     \
-        (d).tail->next = i;       \
+        (i)->prev##n = (d).tail;  \
+        (d).tail->next##n = i;    \
     } else {                      \
         (d).head = i;             \
-        (i)->prev = 0;            \
+        (i)->prev##n = 0;         \
         CT_ASSERT((d).size == 0); \
     }                             \
-    (i)->next = 0;                \
+    (i)->next##n = 0;             \
     (d).tail = i;                 \
     (d).size++;                   \
 } while (0)
+#define DEQ_INSERT_TAIL(d,i) DEQ_INSERT_TAIL_N(,d,i)
 
-#define DEQ_REMOVE_HEAD(d)        \
+#define DEQ_REMOVE_HEAD_N(n,d)    \
 do {                              \
     CT_ASSERT((d).head);          \
     if ((d).head) {               \
         (d).scratch = (d).head;   \
-        (d).head = (d).head->next;  \
+        (d).head = (d).head->next##n;  \
         if ((d).head == 0) {      \
             (d).tail = 0;         \
             CT_ASSERT((d).size == 1); \
-        } else                  \
-            (d).head->prev = 0; \
-        (d).size--;             \
-        (d).scratch->next = 0;  \
-        (d).scratch->prev = 0;  \
-    }                           \
+        } else                     \
+            (d).head->prev##n = 0; \
+        (d).size--;                \
+        (d).scratch->next##n = 0;  \
+        (d).scratch->prev##n = 0;  \
+    }                              \
 } while (0)
+#define DEQ_REMOVE_HEAD(d)  DEQ_REMOVE_HEAD_N(,d)
 
-#define DEQ_REMOVE_TAIL(d)      \
+#define DEQ_REMOVE_TAIL_N(n,d)  \
 do {                            \
     CT_ASSERT((d).tail);        \
     if ((d).tail) {             \
         (d).scratch = (d).tail; \
-        (d).tail = (d).tail->prev;  \
+        (d).tail = (d).tail->prev##n;  \
         if ((d).tail == 0) {    \
             (d).head = 0;       \
             CT_ASSERT((d).size == 1); \
         } else                  \
-            (d).tail->next = 0; \
+            (d).tail->next##n = 0; \
         (d).size--;             \
-        (d).scratch->next = 0;  \
-        (d).scratch->prev = 0;  \
+        (d).scratch->next##n = 0;  \
+        (d).scratch->prev##n = 0;  \
     }                           \
 } while (0)
-
-#define DEQ_INSERT_AFTER(d,i,a) \
-do {                            \
-    CT_ASSERT((i)->next == 0);  \
-    CT_ASSERT((i)->prev == 0);  \
-    CT_ASSERT(a);               \
-    if ((a)->next)              \
-        (a)->next->prev = (i);  \
-    else                        \
-        (d).tail = (i);         \
-    (i)->next = (a)->next;      \
-    (i)->prev = (a);            \
-    (a)->next = (i);            \
-    (d).size++;                 \
+#define DEQ_REMOVE_TAIL(d) DEQ_REMOVE_TAIL_N(,d)
+
+#define DEQ_INSERT_AFTER_N(n,d,i,a) \
+do {                                \
+    CT_ASSERT((i)->next##n == 0);   \
+    CT_ASSERT((i)->prev##n == 0);   \
+    CT_ASSERT(a);                   \
+    if ((a)->next##n)               \
+        (a)->next##n->prev##n = (i);  \
+    else                            \
+        (d).tail = (i);             \
+    (i)->next##n = (a)->next##n;    \
+    (i)->prev##n = (a);             \
+    (a)->next##n = (i);             \
+    (d).size++;                     \
 } while (0)
+#define DEQ_INSERT_AFTER(d,i,a) DEQ_INSERT_AFTER_N(,d,i,a)
 
-#define DEQ_REMOVE(d,i)                        \
+#define DEQ_REMOVE_N(n,d,i)                    \
 do {                                           \
-    if ((i)->next)                             \
-        (i)->next->prev = (i)->prev;           \
+    if ((i)->next##n)                          \
+        (i)->next##n->prev##n = (i)->prev##n;  \
     else                                       \
-        (d).tail = (i)->prev;                  \
-    if ((i)->prev)                             \
-        (i)->prev->next = (i)->next;           \
+        (d).tail = (i)->prev##n;               \
+    if ((i)->prev##n)                          \
+        (i)->prev##n->next##n = (i)->next##n;  \
     else                                       \
-        (d).head = (i)->next;                  \
+        (d).head = (i)->next##n;               \
     (d).size--;                                \
-    (i)->next = 0;                             \
-    (i)->prev = 0;                             \
+    (i)->next##n = 0;                          \
+    (i)->prev##n = 0;                          \
     CT_ASSERT((d).size || (!(d).head && !(d).tail)); \
 } while (0)
+#define DEQ_REMOVE(d,i) DEQ_REMOVE_N(,d,i)
 
-#define DEQ_APPEND(d1,d2)               \
+#define DEQ_APPEND_N(n,d1,d2)           \
 do {                                    \
     if (!(d1).head)                     \
         (d1) = (d2);                    \
     else if ((d2).head) {               \
-        (d1).tail->next = (d2).head;    \
-        (d2).head->prev = (d1).tail;    \
+        (d1).tail->next##n = (d2).head; \
+        (d2).head->prev##n = (d1).tail; \
         (d1).tail = (d2).tail;          \
         (d1).size += (d2).size;         \
     }                                   \
     DEQ_INIT(d2);                       \
 } while (0)
+#define DEQ_APPEND(d1,d2) DEQ_APPEND_N(,d1,d2)
 
 #endif

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/c72e179e/tests/tool_test.c
----------------------------------------------------------------------
diff --git a/tests/tool_test.c b/tests/tool_test.c
index a4ce830..4b68edc 100644
--- a/tests/tool_test.c
+++ b/tests/tool_test.c
@@ -32,6 +32,15 @@ typedef struct item_t {
 DEQ_DECLARE(item_t, item_list_t);
 
 
+typedef struct multi_item_t {
+    DEQ_LINKS(struct multi_item_t);
+    DEQ_LINKS_N(second, struct multi_item_t);
+    char letter;
+} multi_item_t;
+
+DEQ_DECLARE(multi_item_t, multi_item_list_t);
+
+
 static char* list_well_formed(item_list_t list, char *key)
 {
     item_t *ptr;
@@ -190,6 +199,52 @@ static char* test_deq_basic2(void *context)
 }
 
 
+static char* test_deq_multi(void *context)
+{
+    multi_item_list_t  list1;
+    multi_item_list_t  list2;
+    multi_item_t       item[10];
+    multi_item_t      *ptr;
+    int                idx;
+
+    DEQ_INIT(list1);
+    DEQ_INIT(list2);
+    if (DEQ_SIZE(list1) != 0) return "Expected zero initial size 1";
+    if (DEQ_SIZE(list2) != 0) return "Expected zero initial size 2";
+
+    for (idx = 0; idx < 10; idx++) {
+        DEQ_ITEM_INIT(&item[idx]);
+        DEQ_ITEM_INIT_N(second, &item[idx]);
+        item[idx].letter = '0' + idx;
+
+        DEQ_INSERT_TAIL(list1, &item[idx]);
+        if ((idx & 1) == 0) // even index
+            DEQ_INSERT_TAIL_N(second, list2, &item[idx]);
+    }
+
+    if (DEQ_SIZE(list1) != 10) return "Expected list 1 size to be 10";
+    if (DEQ_SIZE(list2) != 5)  return "Expected list 2 size to be 5";
+
+    idx = 0;
+    while (DEQ_HEAD(list1)) {
+        ptr = DEQ_HEAD(list1);
+        DEQ_REMOVE_HEAD(list1);
+        if (ptr->letter != '0' + idx) return "Incorrect value in list 1";
+        idx++;
+    }
+
+    idx = 0;
+    while (DEQ_HEAD(list2)) {
+        ptr = DEQ_HEAD(list2);
+        DEQ_REMOVE_HEAD_N(second, list2);
+        if (ptr->letter != '0' + idx) return "Incorrect value in list 2";
+        idx += 2;
+    }
+
+    return 0;
+}
+
+
 static char* test_bitmask(void *context)
 {
     qd_bitmask_t *bm;
@@ -257,6 +312,7 @@ int tool_tests(void)
 
     TEST_CASE(test_deq_basic, 0);
     TEST_CASE(test_deq_basic2, 0);
+    TEST_CASE(test_deq_multi, 0);
     TEST_CASE(test_bitmask, 0);
 
     return result;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message