mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-19 15:43:56 +00:00
Ring_buffer: add 'avail_capacity()' function
The 'avail_capacity()' function returns how many more elements would currently fit into the ring buffer. Fixes #921.
This commit is contained in:
committed by
Christian Helmuth
parent
7296735816
commit
dc8fc1a33c
@ -89,7 +89,18 @@ class Ring_buffer
|
|||||||
/**
|
/**
|
||||||
* Return true if ring buffer is empty
|
* Return true if ring buffer is empty
|
||||||
*/
|
*/
|
||||||
bool empty() { return _tail == _head; }
|
bool empty() const { return _tail == _head; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the remaining capacity
|
||||||
|
*/
|
||||||
|
int avail_capacity() const
|
||||||
|
{
|
||||||
|
if (_head >= _tail)
|
||||||
|
return QUEUE_SIZE - _head + _tail - 1;
|
||||||
|
else
|
||||||
|
return _tail - _head - 1;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _INCLUDE__OS__RING_BUFFER_H_ */
|
#endif /* _INCLUDE__OS__RING_BUFFER_H_ */
|
||||||
|
Reference in New Issue
Block a user