*
* @author Philip Levis
* @author Kyle Jamieson
+ * @author Geoffrey Mainland
* @date $Date$
*/
implementation {
uint8_t free;
uint8_t index;
- pool_t* queue[size];
+ pool_t* ONE_NOK queue[size];
pool_t pool[size];
command error_t Init.init() {
}
command bool Pool.empty() {
+ dbg("PoolP", "%s size is %i\n", __FUNCTION__, (int)free);
return free == 0;
}
command uint8_t Pool.size() {
+ dbg("PoolP", "%s size is %i\n", __FUNCTION__, (int)free);
return free;
}
pool_t* rval = queue[index];
queue[index] = NULL;
free--;
- index = (index + 1) % size;
+ index++;
+ if (index == size) {
+ index = 0;
+ }
+ dbg("PoolP", "%s size is %i\n", __FUNCTION__, (int)free);
return rval;
}
return NULL;
return FAIL;
}
else {
- uint8_t emptyIndex = (index + free) % size;
+ uint16_t emptyIndex = (index + free);
+ if (emptyIndex >= size) {
+ emptyIndex -= size;
+ }
queue[emptyIndex] = newVal;
free++;
+ dbg("PoolP", "%s size is %i\n", __FUNCTION__, (int)free);
return SUCCESS;
}
}