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<class kind, int length> RingBuffer<kind, length>::RingBuffer(){
this->head = this->tail = 0;
}
template<class kind, int length> int RingBuffer<kind, length>::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<class kind, int length> int RingBuffer<kind, length>::next_block_index(int index){
this->tail = (tail+1)&(length-1);
}
+template<class kind, int length> kind* RingBuffer<kind, length>::get_tail_ref(){
+ return &(buffer[tail]);
+}
+
template<class kind, int length> void RingBuffer<kind, length>::get(int index, kind &object){
int j= 0;
int k= this->head;