FreeRDP
TPCircularBuffer.h File Reference
#include <libkern/OSAtomic.h>
#include <string.h>
#include <assert.h>
This graph shows which files directly or indirectly include this file:

Data Structures

struct  TPCircularBuffer
 

Functions

bool TPCircularBufferInit (TPCircularBuffer *buffer, int32_t length)
 
void TPCircularBufferCleanup (TPCircularBuffer *buffer)
 
void TPCircularBufferClear (TPCircularBuffer *buffer)
 
static __inline__ __attribute__ ((always_inline)) void *TPCircularBufferTail(TPCircularBuffer *buffer
 
 return (void *)((char *) buffer-> buffer+buffer->tail)
 
 OSAtomicAdd32Barrier (-amount,&buffer->fillCount)
 
 assert (buffer->fillCount >=0)
 
 OSAtomicAdd32Barrier (amount,&buffer->fillCount)
 
 assert (buffer->fillCount<=buffer->length)
 
 if (space< len) return false
 
 memcpy (ptr, src, len)
 
 TPCircularBufferProduce (buffer, len)
 

Variables

static __inline__ int32_t * availableBytes
 
if availableBytes return NULL
 
static __inline__ int32_t amount
 
buffer fillCount = amount
 
static __inline__ const voidsrc
 
static __inline__ const void int32_t len
 
voidptr = TPCircularBufferHead(buffer, &space)
 
return true
 

Function Documentation

static __inline__ __attribute__ ( (always_inline)  )
static

Access end of buffer

This gives you a pointer to the end of the buffer, ready for reading, and the number of available bytes to read.

Parameters
bufferCircular buffer
availableBytesOn output, the number of bytes ready for reading
Returns
Pointer to the first bytes ready for reading, or NULL if buffer is empty

Consume bytes in buffer

This frees up the just-read bytes, ready for writing again.

Parameters
bufferCircular buffer
amountNumber of bytes to consume

Version of TPCircularBufferConsume without the memory barrier, for more optimal use in single-threaded contexts

Access front of buffer

This gives you a pointer to the front of the buffer, ready for writing, and the number of available bytes to write.

Parameters
bufferCircular buffer
availableBytesOn output, the number of bytes ready for writing
Returns
Pointer to the first bytes ready for writing, or NULL if buffer is full

Produce bytes in buffer

This marks the given section of the buffer ready for reading.

Parameters
bufferCircular buffer
amountNumber of bytes to produce

Version of TPCircularBufferProduce without the memory barrier, for more optimal use in single-threaded contexts

Helper routine to copy bytes to buffer

This copies the given bytes to the buffer, and marks them ready for writing.

Parameters
bufferCircular buffer
srcSource buffer
lenNumber of bytes in source buffer
Returns
true if bytes copied, false if there was insufficient space
assert ( buffer->fillCount >=  0)
assert ( buffer->fillCount<=buffer->  length)
if ( )
memcpy ( ptr  ,
src  ,
len   
)
OSAtomicAdd32Barrier ( amount,
&buffer->  fillCount 
)
OSAtomicAdd32Barrier ( amount  ,
&buffer->  fillCount 
)
return ( void ) -> buffer+buffer->tail)

Here is the caller graph for this function:

void TPCircularBufferCleanup ( TPCircularBuffer buffer)

Cleanup buffer

Releases buffer resources.

Here is the caller graph for this function:

void TPCircularBufferClear ( TPCircularBuffer buffer)

Clear buffer

Resets buffer to original, empty state.

This is safe for use by consumer while producer is accessing buffer.

Here is the caller graph for this function:

bool TPCircularBufferInit ( TPCircularBuffer buffer,
int32_t  length 
)

Initialise buffer

Note that the length is advisory only: Because of the way the memory mirroring technique works, the true buffer length will be multiples of the device page size (e.g. 4096 bytes)

Parameters
bufferCircular buffer
lengthLength of buffer
TPCircularBufferProduce ( buffer  ,
len   
)

Variable Documentation

static __inline__ int amount
Initial value:
{
buffer->tail = (buffer->tail + amount) % buffer->length
static __inline__ int32_t amount
Definition: TPCircularBuffer.h:116
static __inline__ int32_t * availableBytes
Initial value:
{
*availableBytes = buffer->fillCount
static __inline__ int32_t * availableBytes
Definition: TPCircularBuffer.h:102
buffer fillCount = amount
__inline__ const void int32_t len
Initial value:
{
int32_t space
void* ptr = TPCircularBufferHead(buffer, &space)
__inline__ const void* src
return true