]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/system/QueueC.nc
Merge TinyOS 2.1.1 into master.
[tinyos-2.x.git] / tos / system / QueueC.nc
index c1fcfd084c35670ed4f60b97cde613095cb3b013..ecf714aabed9f3c9221104001e4ce80cab0a74ab 100644 (file)
@@ -34,6 +34,7 @@
  *  A general FIFO queue component, whose queue has a bounded size.
  *
  *  @author Philip Levis
+ *  @author Geoffrey Mainland
  *  @date   $Date$
  */
 
@@ -44,7 +45,7 @@ generic module QueueC(typedef queue_t, uint8_t QUEUE_SIZE) {
 
 implementation {
 
-  queue_t queue[QUEUE_SIZE];
+  queue_t ONE_NOK queue[QUEUE_SIZE];
   uint8_t head = 0;
   uint8_t tail = 0;
   uint8_t size = 0;
@@ -86,7 +87,7 @@ implementation {
     dbg("QueueC", "%s: size is %hhu\n", __FUNCTION__, size);
     if (!call Queue.empty()) {
       head++;
-      head %= QUEUE_SIZE;
+      if (head == QUEUE_SIZE) head = 0;
       size--;
       printQueue();
     }
@@ -98,7 +99,7 @@ implementation {
       dbg("QueueC", "%s: size is %hhu\n", __FUNCTION__, size);
       queue[tail] = newVal;
       tail++;
-      tail %= QUEUE_SIZE;
+      if (tail == QUEUE_SIZE) tail = 0;
       size++;
       printQueue();
       return SUCCESS;
@@ -110,7 +111,9 @@ implementation {
   
   command queue_t Queue.element(uint8_t idx) {
     idx += head;
-    idx %= QUEUE_SIZE;
+    if (idx >= QUEUE_SIZE) {
+      idx -= QUEUE_SIZE;
+    }
     return queue[idx];
   }