mpmc-queue: improve driver, to read all items from queue
authorBrian Norris <banorris@uci.edu>
Thu, 1 Nov 2012 19:19:58 +0000 (12:19 -0700)
committerBrian Norris <banorris@uci.edu>
Thu, 1 Nov 2012 19:19:58 +0000 (12:19 -0700)
threadB() will now read all currently available items from the queue.

mpmc-queue/mpmc-queue.cc

index 146f11e..17713cb 100644 (file)
@@ -15,9 +15,11 @@ void threadA(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
 
 void threadB(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
 {
 
 void threadB(struct mpmc_boundq_1_alt<int32_t, sizeof(int32_t)> *queue)
 {
-       int32_t *bin = queue->read_fetch();
-       printf("Read: %d\n", load_32(bin));
-       queue->read_consume();
+       int32_t *bin;
+       while (bin = queue->read_fetch()) {
+               printf("Read: %d\n", load_32(bin));
+               queue->read_consume();
+       }
 }
 
 int user_main(int argc, char **argv)
 }
 
 int user_main(int argc, char **argv)