include/ring.h File Reference

Simple and efficient ring buffer implementation. More...

#include <stdbool.h>

Include dependency graph for ring.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ring_head
 Ring buffer management data. More...

Functions

static unsigned long ring_get_head (struct ring_head *ring, unsigned long ring_size)
 Get the offset of the next unused entry in the buffer.
static unsigned long ring_get_tail (struct ring_head *ring, unsigned long ring_size)
 Get the offset of the first used entry in the buffer.
static unsigned long ring_entries_used (struct ring_head *ring, unsigned long ring_size)
 Get the number of used entries in the buffer.
static unsigned long ring_entries_used_before_end (struct ring_head *ring, unsigned long ring_size)
 Get the number of used entries in the buffer before it wraps.
static unsigned long ring_entries_unused (struct ring_head *ring, unsigned long ring_size)
 Get the number of unused entries in the buffer.
static unsigned long ring_entries_unused_before_end (struct ring_head *ring, unsigned long ring_size)
 Get the number of unused entries in the buffer before it wraps.
static bool ring_is_empty (struct ring_head *ring, unsigned long ring_size)
 Test if the ring buffer is empty.
static void ring_insert_entries (struct ring_head *ring, unsigned long nr_entries)
 Insert entries into a ring buffer.
static void ring_extract_entries (struct ring_head *ring, unsigned long nr_entries)
 Extract entries from a ring buffer.
static void ring_reset (struct ring_head *ring)
 Reset the ring buffer.


Detailed Description

Simple and efficient ring buffer implementation.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file ring.h.


Function Documentation

static unsigned long ring_entries_unused ( struct ring_head ring,
unsigned long  ring_size 
) [inline, static]

Get the number of unused entries in the buffer.

Parameters:
ring The ring buffer
ring_size The total number of entries in the ring buffer
Returns:
The number of entries which can be inserted before the buffer is full.

Definition at line 187 of file ring.h.

References ring_entries_used().

Referenced by console_buf_unused().

Here is the call graph for this function:

static unsigned long ring_entries_unused_before_end ( struct ring_head ring,
unsigned long  ring_size 
) [inline, static]

Get the number of unused entries in the buffer before it wraps.

Parameters:
ring The ring buffer
ring_size The total number of entries in the ring buffer
Returns:
The number of entries which can be inserted before the buffer is full or wraps around to the beginning.

Definition at line 203 of file ring.h.

References ring_head::head, and ring_head::tail.

Referenced by console_buf_unused_before_end().

static unsigned long ring_entries_used ( struct ring_head ring,
unsigned long  ring_size 
) [inline, static]

Get the number of used entries in the buffer.

Parameters:
ring The ring buffer
ring_size The total number of entries in the ring buffer
Returns:
The number of entries which can be extracted before the buffer is empty.

Definition at line 147 of file ring.h.

References ring_head::head, and ring_head::tail.

Referenced by console_buf_used(), and ring_entries_unused().

static unsigned long ring_entries_used_before_end ( struct ring_head ring,
unsigned long  ring_size 
) [inline, static]

Get the number of used entries in the buffer before it wraps.

Parameters:
ring The ring buffer
ring_size The total number of entries in the ring buffer
Returns:
The number of entries which can be extracted before the buffer is empty or wraps around to the beginning.

Definition at line 164 of file ring.h.

References ring_head::head, and ring_head::tail.

static void ring_extract_entries ( struct ring_head ring,
unsigned long  nr_entries 
) [inline, static]

Extract entries from a ring buffer.

Adjust the buffer tail to account for entries being extracted from the buffer. Normally, this should be called after the actual buffer contents have been read; the barrier ensures that the compiler doesn't move any buffer accesses after updating the tail.

Parameters:
ring The ring buffer
nr_entries The number of entries to extract

Definition at line 261 of file ring.h.

References barrier, and ring_head::tail.

Referenced by console_buf_extract_char().

static unsigned long ring_get_head ( struct ring_head ring,
unsigned long  ring_size 
) [inline, static]

Get the offset of the next unused entry in the buffer.

Note that the value returned by this function is only meaningful if there actually are any unused entries in the buffer.

Parameters:
ring The ring buffer
ring_size The total number of entries in the ring buffer
Returns:
The offset into the buffer of the next unused entry.

Definition at line 111 of file ring.h.

References ring_head::head.

Referenced by console_buf_insert_char(), and console_drv_write().

static unsigned long ring_get_tail ( struct ring_head ring,
unsigned long  ring_size 
) [inline, static]

Get the offset of the first used entry in the buffer.

Note that the value returned by this function is only meaningful if there actually are any used entries in the buffer.

Parameters:
ring The ring buffer
ring_size The total number of entries in the ring buffer
Returns:
The offset into the buffer of the first used entry.

Definition at line 130 of file ring.h.

References ring_head::tail.

Referenced by console_buf_extract_char().

static void ring_insert_entries ( struct ring_head ring,
unsigned long  nr_entries 
) [inline, static]

Insert entries into a ring buffer.

Adjust the buffer head to account for entries being inserted into the buffer. Normally, this should be called after the actual buffer contents have been updated; the barrier ensures that the compiler doesn't move any buffer accesses after updating the head.

Parameters:
ring The ring buffer
nr_entries The number of entries to insert

Definition at line 243 of file ring.h.

References barrier, and ring_head::head.

Referenced by console_buf_insert_char(), and console_drv_write().

static bool ring_is_empty ( struct ring_head ring,
unsigned long  ring_size 
) [inline, static]

Test if the ring buffer is empty.

Parameters:
ring The ring buffer
ring_size The total number of entries in the ring buffer
Return values:
true There are no used entries in the buffer.
false There is at least one used entry in the buffer.

Definition at line 226 of file ring.h.

References ring_head::head, and ring_head::tail.

static void ring_reset ( struct ring_head ring  )  [inline, static]

Reset the ring buffer.

This will mark the ring buffer as empty, and move both head and tail to the beginning of the buffer.

Parameters:
ring The ring buffer

Definition at line 276 of file ring.h.

References ring_head::head, and ring_head::tail.


Generated on Tue Sep 15 10:21:24 2009 for libavr32 by  doxygen 1.5.8