Thread-safe ringbuffer implementation.  
More...
Thread-safe ringbuffer implementation. 
- Attention
 - Buffer size must be a power of two! 
 
 | 
| file   | tsrb.h | 
|   | Thread-safe ringbuffer interface definition. 
  | 
|   | 
 | 
| #define  | TSRB_INIT(BUF)   { (BUF), sizeof (BUF), 0, 0 } | 
|   | Static initializer.  More...
  | 
|   | 
 | 
| 
typedef struct tsrb  | tsrb_t | 
|   | thread-safe ringbuffer struct 
  | 
|   | 
 | 
| static void  | tsrb_init (tsrb_t *rb, uint8_t *buffer, unsigned bufsize) | 
|   | Initialize a tsrb.  More...
  | 
|   | 
| static void  | tsrb_clear (tsrb_t *rb) | 
|   | Clear a tsrb.  More...
  | 
|   | 
| static int  | tsrb_empty (const tsrb_t *rb) | 
|   | Test if the tsrb is empty.  More...
  | 
|   | 
| static unsigned int  | tsrb_avail (const tsrb_t *rb) | 
|   | Get number of bytes available for reading.  More...
  | 
|   | 
| static int  | tsrb_full (const tsrb_t *rb) | 
|   | Test if the tsrb is full.  More...
  | 
|   | 
| static unsigned int  | tsrb_free (const tsrb_t *rb) | 
|   | Get free space in ringbuffer.  More...
  | 
|   | 
| int  | tsrb_get_one (tsrb_t *rb) | 
|   | Get a byte from ringbuffer.  More...
  | 
|   | 
| int  | tsrb_peek_one (tsrb_t *rb) | 
|   | Get a byte from ringbuffer, without removing it.  More...
  | 
|   | 
| int  | tsrb_get (tsrb_t *rb, uint8_t *dst, size_t n) | 
|   | Get bytes from ringbuffer.  More...
  | 
|   | 
| int  | tsrb_peek (tsrb_t *rb, uint8_t *dst, size_t n) | 
|   | Get bytes from ringbuffer, without removing them.  More...
  | 
|   | 
| int  | tsrb_drop (tsrb_t *rb, size_t n) | 
|   | Drop bytes from ringbuffer.  More...
  | 
|   | 
| int  | tsrb_add_one (tsrb_t *rb, uint8_t c) | 
|   | Add a byte to ringbuffer.  More...
  | 
|   | 
| int  | tsrb_add (tsrb_t *rb, const uint8_t *src, size_t n) | 
|   | Add bytes to ringbuffer.  More...
  | 
|   | 
◆ TSRB_INIT
      
        
          | #define TSRB_INIT | 
          ( | 
            | 
          BUF | ) | 
             { (BUF), sizeof (BUF), 0, 0 } | 
        
      
 
Static initializer. 
- Note
 - The size of the buffer (
sizeof(@p BUF)) must be a power of two. 
- Parameters
 - 
  
    | [in] | BUF | Buffer to use by tsrb.  | 
  
   
Definition at line 52 of file tsrb.h.
 
 
◆ tsrb_add()
      
        
          | int tsrb_add  | 
          ( | 
          tsrb_t *  | 
          rb,  | 
        
        
           | 
           | 
          const uint8_t *  | 
          src,  | 
        
        
           | 
           | 
          size_t  | 
          n  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Add bytes to ringbuffer. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
    | [in] | src | buffer to read from  | 
    | [in] | n | max number of bytes to read from src  | 
  
   
- Returns
 - nr of bytes read from 
src  
 
 
◆ tsrb_add_one()
      
        
          | int tsrb_add_one  | 
          ( | 
          tsrb_t *  | 
          rb,  | 
        
        
           | 
           | 
          uint8_t  | 
          c  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Add a byte to ringbuffer. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
    | [in] | c | Character to add to ringbuffer  | 
  
   
- Returns
 - 0 on success 
 
- 
-1 if no space available 
 
 
 
◆ tsrb_avail()
  
  
      
        
          | static unsigned int tsrb_avail  | 
          ( | 
          const tsrb_t *  | 
          rb | ) | 
           | 
         
       
   | 
  
inlinestatic   | 
  
 
Get number of bytes available for reading. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
  
   
- Returns
 - nr of available bytes 
 
Definition at line 106 of file tsrb.h.
 
 
◆ tsrb_clear()
  
  
      
        
          | static void tsrb_clear  | 
          ( | 
          tsrb_t *  | 
          rb | ) | 
           | 
         
       
   | 
  
inlinestatic   | 
  
 
Clear a tsrb. 
- Parameters
 - 
  
    | [out] | rb | Ringbuffer to operate on  | 
  
   
Definition at line 80 of file tsrb.h.
 
 
◆ tsrb_drop()
      
        
          | int tsrb_drop  | 
          ( | 
          tsrb_t *  | 
          rb,  | 
        
        
           | 
           | 
          size_t  | 
          n  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Drop bytes from ringbuffer. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
    | [in] | n | max number of bytes to drop  | 
  
   
- Returns
 - nr of bytes dropped 
 
 
 
◆ tsrb_empty()
  
  
      
        
          | static int tsrb_empty  | 
          ( | 
          const tsrb_t *  | 
          rb | ) | 
           | 
         
       
   | 
  
inlinestatic   | 
  
 
Test if the tsrb is empty. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
  
   
- Returns
 - 0 if not empty 
 
- 
1 otherwise 
 
Definition at line 93 of file tsrb.h.
 
 
◆ tsrb_free()
  
  
      
        
          | static unsigned int tsrb_free  | 
          ( | 
          const tsrb_t *  | 
          rb | ) | 
           | 
         
       
   | 
  
inlinestatic   | 
  
 
Get free space in ringbuffer. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
  
   
- Returns
 - nr of available bytes 
 
Definition at line 133 of file tsrb.h.
 
 
◆ tsrb_full()
  
  
      
        
          | static int tsrb_full  | 
          ( | 
          const tsrb_t *  | 
          rb | ) | 
           | 
         
       
   | 
  
inlinestatic   | 
  
 
Test if the tsrb is full. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
  
   
- Returns
 - 0 if not full 
 
- 
1 otherwise 
 
Definition at line 120 of file tsrb.h.
 
 
◆ tsrb_get()
      
        
          | int tsrb_get  | 
          ( | 
          tsrb_t *  | 
          rb,  | 
        
        
           | 
           | 
          uint8_t *  | 
          dst,  | 
        
        
           | 
           | 
          size_t  | 
          n  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Get bytes from ringbuffer. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
    | [out] | dst | buffer to write to  | 
    | [in] | n | max number of bytes to write to dst  | 
  
   
- Returns
 - nr of bytes written to 
dst  
 
 
◆ tsrb_get_one()
      
        
          | int tsrb_get_one  | 
          ( | 
          tsrb_t *  | 
          rb | ) | 
           | 
        
      
 
Get a byte from ringbuffer. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
  
   
- Returns
 - >=0 byte that has been read 
 
- 
-1 if no byte available 
 
 
 
◆ tsrb_init()
  
  
      
        
          | static void tsrb_init  | 
          ( | 
          tsrb_t *  | 
          rb,  | 
         
        
           | 
           | 
          uint8_t *  | 
          buffer,  | 
         
        
           | 
           | 
          unsigned  | 
          bufsize  | 
         
        
           | 
          ) | 
           |  | 
         
       
   | 
  
inlinestatic   | 
  
 
Initialize a tsrb. 
- Note
 - The size of the buffer (
bufsize) must be a power of two. 
- Parameters
 - 
  
    | [out] | rb | Datum to initialize.  | 
    | [in] | buffer | Buffer to use by tsrb.  | 
    | [in] | bufsize | Size of buffer.  | 
  
   
Definition at line 63 of file tsrb.h.
 
 
◆ tsrb_peek()
      
        
          | int tsrb_peek  | 
          ( | 
          tsrb_t *  | 
          rb,  | 
        
        
           | 
           | 
          uint8_t *  | 
          dst,  | 
        
        
           | 
           | 
          size_t  | 
          n  | 
        
        
           | 
          ) | 
           |  | 
        
      
 
Get bytes from ringbuffer, without removing them. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
    | [out] | dst | buffer to write to  | 
    | [in] | n | max number of bytes to write to dst  | 
  
   
- Returns
 - nr of bytes written to 
dst  
 
 
◆ tsrb_peek_one()
      
        
          | int tsrb_peek_one  | 
          ( | 
          tsrb_t *  | 
          rb | ) | 
           | 
        
      
 
Get a byte from ringbuffer, without removing it. 
- Parameters
 - 
  
    | [in] | rb | Ringbuffer to operate on  | 
  
   
- Returns
 - >=0 byte that has been read 
 
- 
-1 if no byte available