118 lines
3.1 KiB
C
118 lines
3.1 KiB
C
|
|
#ifndef __CELOXICA_BUFFERPOOL_H__
|
|
#define __CELOXICA_BUFFERPOOL_H__
|
|
|
|
#include <limits.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define CELOXICA_BUFFER_POOL_MAX_BLOCKS UINT_MAX
|
|
|
|
typedef struct _CeloxicaBuffer CeloxicaBuffer_t;
|
|
|
|
typedef struct _CeloxicaBufferPoolHandle CeloxicaBufferPoolHandle_t;
|
|
|
|
/**
|
|
* \brief Open Celoxica buffer pool
|
|
*
|
|
* The bufferpool library allocates buffers in blocks. Each block will contain a predefined number of items (BlockSize).
|
|
*
|
|
* @param H Buffer pool handle pointer
|
|
* @param BlockSize The number of items in each buffer.
|
|
* @param DataSize The size of each item.
|
|
*
|
|
* @return zero on successful completion.
|
|
*/
|
|
int CeloxicaBufferPoolOpen(CeloxicaBufferPoolHandle_t **H, unsigned int BlockSize, unsigned int MaxBlocks, size_t DataSize);
|
|
|
|
/**
|
|
* \brief Close Celoxica buffer pool
|
|
*
|
|
* @param H Buffer pool handle
|
|
*
|
|
* @return zero on successful completion.
|
|
*/
|
|
int CeloxicaBufferPoolClose(CeloxicaBufferPoolHandle_t *H);
|
|
|
|
/**
|
|
* \brief Add new buffer to pool
|
|
*
|
|
* This function will add a new buffer to allocated and resize the allocated array if needed.
|
|
*
|
|
* @param H Buffer pool handle
|
|
*
|
|
* @return zero on successful completion.
|
|
*/
|
|
int CeloxicaBufferPoolAdd(CeloxicaBufferPoolHandle_t *H);
|
|
|
|
/**
|
|
* \brief Get free buffer item.
|
|
*
|
|
* This function will get a buffer free from the buffer pool.
|
|
*
|
|
* @param H Buffer pool handle
|
|
* @param Buf The pointer to free buffer.
|
|
*
|
|
* @return zero on successful completion.
|
|
*/
|
|
int CeloxicaBufferPoolGetBuffer(CeloxicaBufferPoolHandle_t *H, CeloxicaBuffer_t **Buf);
|
|
|
|
/**
|
|
* \brief Release buffer item.
|
|
*
|
|
* Push buffer item previously acquired by \ref CeloxicaBufferPoolGetBuffer() back into the buffer pool.
|
|
*
|
|
* @param H Buffer pool handle
|
|
* @param Buf The buffer item.
|
|
*
|
|
* @return zero on successful completion.
|
|
*/
|
|
int CeloxicaBufferPoolRelease(CeloxicaBufferPoolHandle_t *H, CeloxicaBuffer_t *Buf);
|
|
|
|
/**
|
|
* \brief Duplicate a buffer item.
|
|
*
|
|
* Creates a copy of a buffer item.
|
|
*
|
|
* @param H Buffer pool handle
|
|
* @param Orig The buffer item to be copied.
|
|
* @param Dst The destination pointer.
|
|
*
|
|
* @return zero on successful completion.
|
|
*/
|
|
int CeloxicaBufferPoolDup(CeloxicaBufferPoolHandle_t *H, const CeloxicaBuffer_t *Orig, CeloxicaBuffer_t **Dst);
|
|
|
|
/**
|
|
* \brief Get Data Pointer from buffer.
|
|
*
|
|
* Used to get a data pointer from a buffer structure.
|
|
*
|
|
* @param Buf The buffer item.
|
|
*
|
|
* @return A pointer to the data stored in the buffer, or NULL if Buf is invalid.
|
|
*/
|
|
char* CeloxicaBufferPoolGetData(CeloxicaBuffer_t *Buf);
|
|
|
|
/**
|
|
* \brief Get buffer from data pointer.
|
|
*
|
|
* Used to get a pointer to a buffer structure from a data pointer.
|
|
*
|
|
* \note This function will ONLY provide valid behaviour if the data pointer used was previously returned
|
|
* \ref CeloxicaBufferPoolGetData(). If another pointer is provided the behaviour is undefined.
|
|
*
|
|
* @param Data Pointer to a data pointer provied by \ref CeloxicaBufferPoolGetData()
|
|
*
|
|
* @return A pointer to the buffer containing the data, or NULL if Data is NULL.
|
|
*/
|
|
CeloxicaBuffer_t* CeloxicaBufferPoolGetBuf(char *Data);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __Celoxica_BUFFERPOOL_H__ */
|
|
|