FreeRDP
TPCircularBuffer.h File Reference
#include <libkern/OSAtomic.h>
#include <string.h>
#include <winpr/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)
 
 WINPR_ASSERT (buffer->fillCount >=0)
 
 OSAtomicAdd32Barrier (amount, &buffer->fillCount)
 
 WINPR_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 void * src
 
static __inline__ const void int32_t len
 
void * ptr = TPCircularBufferHead(buffer, &space)
 
return true
 

Function Documentation

◆ __attribute__()

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

◆ if()

if ( )
Here is the call graph for this function:

◆ memcpy()

memcpy ( ptr  ,
src  ,
len   
)

◆ OSAtomicAdd32Barrier() [1/2]

OSAtomicAdd32Barrier ( amount,
&buffer->  fillCount 
)

◆ OSAtomicAdd32Barrier() [2/2]

OSAtomicAdd32Barrier ( amount  ,
&buffer->  fillCount 
)

◆ return()

return ( void *  ) -> buffer+buffer->tail)

◆ TPCircularBufferCleanup()

void TPCircularBufferCleanup ( TPCircularBuffer buffer)

Cleanup buffer

Releases buffer resources.

Here is the caller graph for this function:

◆ TPCircularBufferClear()

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:

◆ TPCircularBufferInit()

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()

TPCircularBufferProduce ( buffer  ,
len   
)

◆ WINPR_ASSERT() [1/2]

WINPR_ASSERT ( buffer->fillCount >=  0)

◆ WINPR_ASSERT() [2/2]

WINPR_ASSERT ( buffer->fillCount<=buffer->  length)

Variable Documentation

◆ amount

static __inline__ int amount
Initial value:
{
buffer->tail = (buffer->tail + amount) % buffer->length
static __inline__ int32_t amount
Definition: TPCircularBuffer.h:124

◆ availableBytes

static __inline__ int32_t * availableBytes
Initial value:
{
*availableBytes = buffer->fillCount
static __inline__ int32_t * availableBytes
Definition: TPCircularBuffer.h:107

◆ fillCount

buffer fillCount = amount

◆ len

__inline__ const void int32_t len
Initial value:
{
int32_t space

◆ NULL

◆ ptr

void* ptr = TPCircularBufferHead(buffer, &space)

◆ src

__inline__ const void* src

◆ true

return true