Fixes #3964: Added free space check before putting new data into Lua … (#3968)

* Fixes #3964: Added free space check before putting new data into Lua Telemetry Fifo

* Copy-paste error

* Compilation fix

* Another compilation fix
This commit is contained in:
Damjan Adamic
2016-11-02 12:56:43 +01:00
committed by Bertrand Songis
parent 450430f22e
commit a332f7a872
3 changed files with 15 additions and 8 deletions
+10 -3
View File
@@ -24,6 +24,8 @@
template <class T, int N>
class Fifo
{
static_assert((N > 1) & !(N & (N - 1)), "Fifo size must be a power of two!");
public:
Fifo():
widx(0),
@@ -57,7 +59,7 @@ class Fifo
}
}
bool isEmpty()
bool isEmpty() const
{
return (ridx == widx);
}
@@ -73,12 +75,17 @@ class Fifo
while (!isEmpty()) {};
}
uint32_t size()
uint32_t size() const
{
return (N + widx - ridx) & (N-1);
}
bool probe(T & element)
uint32_t hasSpace(uint32_t n) const
{
return (N > (size() + n));
}
bool probe(T & element) const
{
if (isEmpty()) {
return false;