2727
2828namespace arduino {
2929
30-
3130#define FIFO_DEFAULT_SIZE 64
3231
3332template <typename T, uint32_t size = FIFO_DEFAULT_SIZE>
@@ -38,28 +37,30 @@ class FifoBuffer
3837 synchronized {
3938 return (uint32_t )(index + 1 ) % size;
4039 }
40+ return 0 ; // Fallback return
4141 }
42+
4243 inline bool isEmpty () const { return (_numElems == 0 ); }
43- T _aucBuffer[size] ;
44- uint32_t _iHead ;
45- uint32_t _iTail ;
44+ T _aucBuffer[size];
45+ uint32_t _iHead;
46+ uint32_t _iTail;
4647 uint32_t _numElems;
48+
4749 public:
4850 /* ---------------------------------------------------------------------- */
49- FifoBuffer ( void ) {
50- memset ( _aucBuffer, 0 , size * sizeof (T) ) ;
51+ FifoBuffer (void ) {
52+ memset (_aucBuffer, 0 , size * sizeof (T)) ;
5153 clear ();
5254 }
5355 /* ---------------------------------------------------------------------- */
54- bool store ( T c ) {
56+ bool store (T c) {
5557 bool rv = true ;
5658 synchronized {
5759 if (!isFull ()) {
58- _aucBuffer[_iHead] = c ;
60+ _aucBuffer[_iHead] = c;
5961 _iHead = nextIndex (_iHead);
6062 _numElems++;
61- }
62- else {
63+ } else {
6364 rv = false ;
6465 }
6566 }
@@ -72,36 +73,39 @@ class FifoBuffer
7273 _numElems = 0 ;
7374 }
7475 /* ---------------------------------------------------------------------- */
75- T read (bool * read_ok) {
76+ T read (bool * read_ok) {
7677 *read_ok = true ;
7778 if (isEmpty ()) {
7879 *read_ok = false ;
79- return _aucBuffer[ 0 ];
80+ return T (); // Return default-constructed object
8081 }
8182 synchronized {
8283 T value = _aucBuffer[_iTail];
8384 _iTail = nextIndex (_iTail);
8485 _numElems--;
85-
86+
8687 return value;
8788 }
89+ return T (); // Fallback return
8890 }
8991 /* ---------------------------------------------------------------------- */
9092 int available () {
9193 synchronized {
9294 return _numElems;
9395 }
96+ return 0 ; // Fallback return
9497 }
9598 /* ---------------------------------------------------------------------- */
9699 int freePositions () {
97100 synchronized {
98101 return (size - _numElems);
99102 }
103+ return 0 ; // Fallback return
100104 }
101105 /* ---------------------------------------------------------------------- */
102106 T peek () {
103107 if (isEmpty ())
104- return - 1 ;
108+ return T (); // Return default-constructed object
105109
106110 return _aucBuffer[_iTail];
107111 }
@@ -110,15 +114,13 @@ class FifoBuffer
110114 synchronized {
111115 return (_numElems == size);
112116 }
117+ return false ; // Fallback return
113118 }
114119 /* ---------------------------------------------------------------------- */
115- uint32_t lenght () const { return size; }
116-
117-
120+ uint32_t lenght () const { return size; }
118121};
119122
120-
121- } // namespace arduino
123+ } // namespace arduino
122124
123125#endif /* _ARDUINO_FIFO_BUFFER_DH_ */
124- #endif /* __cplusplus */
126+ #endif /* __cplusplus */
0 commit comments