ring_buf
Loading...
Searching...
No Matches
Functions
ring_buf.c File Reference

Ring buffer functions. More...

#include "ring_buf.h"
#include <string.h>
Include dependency graph for ring_buf.c:

Go to the source code of this file.

Functions

static void ring_buf_clamp (ring_buf_size_t *clamp, ring_buf_size_t limit)
 Clamp a value to a specified limit.
 
static ring_buf_size_t ring_buf_zone_head (const struct ring_buf_zone *zone)
 Head index of a zone.
 
static ring_buf_size_t ring_buf_zone_tail (const struct ring_buf_zone *zone)
 Tail index of a zone.
 
static ring_buf_size_t ring_buf_zone_claim (const struct ring_buf_zone *zone)
 Claim size of a zone.
 
static void ring_buf_zone_reset (struct ring_buf_zone *zone, ring_buf_ptrdiff_t base)
 Resets a ring buffer zone.
 
void ring_buf_reset (struct ring_buf *buf, ring_buf_ptrdiff_t base)
 Resets a ring buffer.
 
ring_buf_size_t ring_buf_put_claim (struct ring_buf *buf, void **space, ring_buf_size_t size)
 Claims space for putting data into a ring buffer.
 
int ring_buf_put_ack (struct ring_buf *buf, ring_buf_size_t size)
 Acknowledges space claimed for putting data into a ring buffer.
 
ring_buf_size_t ring_buf_get_claim (struct ring_buf *buf, void **space, ring_buf_size_t size)
 Claims contiguous space for getting.
 
int ring_buf_get_ack (struct ring_buf *buf, ring_buf_size_t size)
 Acknowledges space claimed for getting data from a ring buffer.
 
ring_buf_size_t ring_buf_put (struct ring_buf *buf, const void *data, ring_buf_size_t size)
 Puts non-contiguous bytes into the ring buffer.
 
ring_buf_size_t ring_buf_get (struct ring_buf *buf, void *data, ring_buf_size_t size)
 Gets data from a ring buffer.
 
int ring_buf_put_all (struct ring_buf *buf, const void *data, ring_buf_size_t size)
 Puts all or none.
 
int ring_buf_get_all (struct ring_buf *buf, void *data, ring_buf_size_t size)
 Gets all or none.
 

Detailed Description

Ring buffer functions.

Implements ring buffer functions for putting and getting data, including contiguous and discontiguous access methods. Also includes functions for acknowledging put and get operations, as well as resetting the buffer.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file ring_buf.c.

Function Documentation

◆ ring_buf_clamp()

static void ring_buf_clamp ( ring_buf_size_t clamp,
ring_buf_size_t  limit 
)
inlinestatic

Clamp a value to a specified limit.

Clamps the value pointed to by clamp to limit if it exceeds the limit.

Parameters
clampPointer to the value to clamp.
limitThe limit to clamp the value to.

Definition at line 45 of file ring_buf.c.

◆ ring_buf_zone_claim()

static ring_buf_size_t ring_buf_zone_claim ( const struct ring_buf_zone zone)
inlinestatic

Claim size of a zone.

The claim size is the difference between head and tail.

Parameters
zoneRing buffer zone.
Returns
Claim size.

Definition at line 80 of file ring_buf.c.

◆ ring_buf_zone_head()

static ring_buf_size_t ring_buf_zone_head ( const struct ring_buf_zone zone)
inlinestatic

Head index of a zone.

Used as the wrap size when claiming. The wrap size equals the head relative to the base.

Parameters
zoneRing buffer zone.
Returns
Head index.

Definition at line 59 of file ring_buf.c.

◆ ring_buf_zone_reset()

static void ring_buf_zone_reset ( struct ring_buf_zone zone,
ring_buf_ptrdiff_t  base 
)
inlinestatic

Resets a ring buffer zone.

Sets the base, head, and tail of the zone to the specified base index.

Parameters
zoneRing buffer zone.
baseBase index for the zone.

Definition at line 91 of file ring_buf.c.

◆ ring_buf_zone_tail()

static ring_buf_size_t ring_buf_zone_tail ( const struct ring_buf_zone zone)
inlinestatic

Tail index of a zone.

Parameters
zoneRing buffer zone.
Returns
Tail index.

Definition at line 69 of file ring_buf.c.