Merging upstream version 1.15~rc1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
5fdbdd44aa
commit
ae3eafc693
27 changed files with 724 additions and 791 deletions
28
cbuffer.c
28
cbuffer.c
|
@ -17,15 +17,15 @@
|
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*/
|
||||
|
||||
struct Circular_buffer
|
||||
typedef struct Circular_buffer
|
||||
{
|
||||
uint8_t * buffer;
|
||||
unsigned buffer_size; /* capacity == buffer_size - 1 */
|
||||
unsigned get; /* buffer is empty when get == put */
|
||||
unsigned put;
|
||||
};
|
||||
} Circular_buffer;
|
||||
|
||||
static inline bool Cb_init( struct Circular_buffer * const cb,
|
||||
static inline bool Cb_init( Circular_buffer * const cb,
|
||||
const unsigned buf_size )
|
||||
{
|
||||
cb->buffer_size = buf_size + 1;
|
||||
|
@ -36,38 +36,36 @@ static inline bool Cb_init( struct Circular_buffer * const cb,
|
|||
return cb->buffer != 0;
|
||||
}
|
||||
|
||||
static inline void Cb_free( struct Circular_buffer * const cb )
|
||||
static inline void Cb_free( Circular_buffer * const cb )
|
||||
{ free( cb->buffer ); cb->buffer = 0; }
|
||||
|
||||
static inline void Cb_reset( struct Circular_buffer * const cb )
|
||||
static inline void Cb_reset( Circular_buffer * const cb )
|
||||
{ cb->get = 0; cb->put = 0; }
|
||||
|
||||
static inline unsigned Cb_empty( const struct Circular_buffer * const cb )
|
||||
static inline unsigned Cb_empty( const Circular_buffer * const cb )
|
||||
{ return cb->get == cb->put; }
|
||||
|
||||
static inline unsigned Cb_used_bytes( const struct Circular_buffer * const cb )
|
||||
static inline unsigned Cb_used_bytes( const Circular_buffer * const cb )
|
||||
{ return ( (cb->get <= cb->put) ? 0 : cb->buffer_size ) + cb->put - cb->get; }
|
||||
|
||||
static inline unsigned Cb_free_bytes( const struct Circular_buffer * const cb )
|
||||
static inline unsigned Cb_free_bytes( const Circular_buffer * const cb )
|
||||
{ return ( (cb->get <= cb->put) ? cb->buffer_size : 0 ) - cb->put + cb->get - 1; }
|
||||
|
||||
static inline uint8_t Cb_get_byte( struct Circular_buffer * const cb )
|
||||
static inline uint8_t Cb_get_byte( Circular_buffer * const cb )
|
||||
{
|
||||
const uint8_t b = cb->buffer[cb->get];
|
||||
if( ++cb->get >= cb->buffer_size ) cb->get = 0;
|
||||
return b;
|
||||
}
|
||||
|
||||
static inline void Cb_put_byte( struct Circular_buffer * const cb,
|
||||
const uint8_t b )
|
||||
static inline void Cb_put_byte( Circular_buffer * const cb, const uint8_t b )
|
||||
{
|
||||
cb->buffer[cb->put] = b;
|
||||
if( ++cb->put >= cb->buffer_size ) cb->put = 0;
|
||||
}
|
||||
|
||||
|
||||
static bool Cb_unread_data( struct Circular_buffer * const cb,
|
||||
const unsigned size )
|
||||
static bool Cb_unread_data( Circular_buffer * const cb, const unsigned size )
|
||||
{
|
||||
if( size > Cb_free_bytes( cb ) ) return false;
|
||||
if( cb->get >= size ) cb->get -= size;
|
||||
|
@ -80,7 +78,7 @@ static bool Cb_unread_data( struct Circular_buffer * const cb,
|
|||
If 'out_buffer' is null, the bytes are discarded.
|
||||
Return the number of bytes copied or discarded.
|
||||
*/
|
||||
static unsigned Cb_read_data( struct Circular_buffer * const cb,
|
||||
static unsigned Cb_read_data( Circular_buffer * const cb,
|
||||
uint8_t * const out_buffer,
|
||||
const unsigned out_size )
|
||||
{
|
||||
|
@ -113,7 +111,7 @@ static unsigned Cb_read_data( struct Circular_buffer * const cb,
|
|||
/* Copy up to 'in_size' bytes from 'in_buffer' and update 'put'.
|
||||
Return the number of bytes copied.
|
||||
*/
|
||||
static unsigned Cb_write_data( struct Circular_buffer * const cb,
|
||||
static unsigned Cb_write_data( Circular_buffer * const cb,
|
||||
const uint8_t * const in_buffer,
|
||||
const unsigned in_size )
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue