X-Git-Url: https://git.hcoop.net/clinton/Smoothieware.git/blobdiff_plain/63c274b8077c1a33f1748e8796b4446547ee39aa..d4ee6ee239981a7fbc9fb24849182d5b9e2cee29:/src/libs/RingBuffer.h?ds=sidebyside diff --git a/src/libs/RingBuffer.h b/src/libs/RingBuffer.h index 65a6d81d..20c11282 100644 --- a/src/libs/RingBuffer.h +++ b/src/libs/RingBuffer.h @@ -20,15 +20,17 @@ template class RingBuffer { int prev_block_index(int index); void push_back(kind object); void pop_front(kind &object); + kind* get_tail_ref(); void get( int index, kind &object); kind* get_ref( int index); void delete_first(); kind buffer[length]; - int head; - int tail; + volatile int head; + volatile int tail; }; +#include "sLPC17xx.h" template RingBuffer::RingBuffer(){ this->head = this->tail = 0; @@ -39,7 +41,11 @@ template int RingBuffer::capacity(){ } template int RingBuffer::size(){ -return((this->head>this->tail)?length:0)+this->tail-head; + //return((this->head>this->tail)?length:0)+this->tail-head; + __disable_irq(); + int i = tail - head + ((head > tail)?length:0); + __enable_irq(); + return i; } template int RingBuffer::next_block_index(int index){ @@ -59,6 +65,10 @@ template void RingBuffer::push_back(kind o this->tail = (tail+1)&(length-1); } +template kind* RingBuffer::get_tail_ref(){ + return &(buffer[tail]); +} + template void RingBuffer::get(int index, kind &object){ int j= 0; int k= this->head;