]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
opr: Don't confuse isLast and isEnd
authorSimon Wilkinson <sxw@your-file-system.com>
Wed, 21 Nov 2012 16:46:29 +0000 (16:46 +0000)
committerDerrick Brashear <shadow@your-file-system.com>
Fri, 23 Nov 2012 14:18:31 +0000 (06:18 -0800)
opr_queue_IsEnd's implementation was incorrect - it would return
true when the element was the last item in the list, not when it
was the end of the list (equal to the head record)

Correct the implementation of isEnd, and add an implementation for
isLast.

This fixes a bug in RX, wher we would never notice that the last
packet in the transmit queue was acknowledged, because the loop that
iterates over the queue uses isEnd to detect when its work is done.

Change-Id: I8966e05c479c18d025bb5cc4cf77514ce002be95
Reviewed-on: http://gerrit.openafs.org/8493
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
src/opr/queue.h
tests/opr/queues-t.c

index dd45f68d75682795b3c5b4cd65feb5f022f7a1e7..e31c9024fe488a4b836a62b4196272164a337c2b 100644 (file)
@@ -124,6 +124,11 @@ opr_queue_IsOnQueue(struct opr_queue *q) {
 
 static_inline int
 opr_queue_IsEnd(struct opr_queue *q, struct opr_queue *cursor) {
+    return (cursor == q);
+}
+
+static_inline int
+opr_queue_IsLast(struct opr_queue *q, struct opr_queue *cursor) {
     return (cursor->next == q);
 }
 
index 257e519802326b9504b4dbae50e2ac151ce6316b..df43f5d3c29d15b89715dc0df6b6aeba3634467d 100644 (file)
@@ -57,7 +57,7 @@ main(void)
 {
     struct opr_queue q1, q2, q3, q4, *cursor;
 
-    plan(17);
+    plan(20);
 
     opr_queue_Init(&q1);
     opr_queue_Init(&q2);
@@ -136,5 +136,13 @@ main(void)
     is_string("ABC", queueAsString(&q3), "Swap Q3");
     is_string("123", queueAsString(&q4), "Swap Q4");
 
+    /* IsEnd and IsLast handling */
+    ok(opr_queue_IsLast(&q1, &(opr_queue_Last(&q1, struct charqueue, entry)->entry)),
+       "IsLast is true for last element of a list");
+    ok(opr_queue_IsEnd(&q1,
+                      opr_queue_Last(&q1, struct charqueue, entry)->entry.next),
+       "IsEnd is true for entry after last element");
+    ok(opr_queue_IsEnd(&q1, &q1), "IsEnd is true for queue head");
+
     return 0;
 }