]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/system/PoolP.nc
Merge over into the trunk.
[tinyos-2.x.git] / tos / system / PoolP.nc
index 960b03baea14a18373b17a647a3be8d86d122161..0dc44e5319d1c1b1d54cd1b3c94f3994e99c5da5 100644 (file)
@@ -46,6 +46,7 @@
  *
  *  @author Philip Levis
  *  @author Kyle Jamieson
+ *  @author Geoffrey Mainland
  *  @date   $Date$
  */
 
@@ -87,7 +88,10 @@ implementation {
       pool_t* rval = queue[index];
       queue[index] = NULL;
       free--;
-      index = (index + 1) % size;
+      index++;
+      if (index == size) {
+        index = 0;
+      }
       return rval;
     }
     return NULL;
@@ -98,7 +102,10 @@ implementation {
       return FAIL;
     }
     else {
-      uint8_t emptyIndex = (index + free) % size;
+      uint8_t emptyIndex = (index + free);
+      if (emptyIndex >= size) {
+        emptyIndex -= size;
+      }
       queue[emptyIndex] = newVal;
       free++;
       return SUCCESS;