CDI SDK
SDK for transporting chunks of data reliably and with low latency using a polled mode network driver.
Loading...
Searching...
No Matches
cdi_pool_api.h
Go to the documentation of this file.
1// -------------------------------------------------------------------------------------------
2// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3// This file is part of the AWS CDI-SDK, licensed under the BSD 2-Clause "Simplified" License.
4// License details at: https://github.com/aws/aws-cdi-sdk/blob/mainline/LICENSE
5// -------------------------------------------------------------------------------------------
6
79#ifndef CDI_POOL_API_H__
80#define CDI_POOL_API_H__
81
82#include <stdbool.h>
83#include <stdint.h>
84
85#include "cdi_utility_api.h"
86
87//*********************************************************************************************************************
88//***************************************** START OF DEFINITIONS AND TYPES ********************************************
89//*********************************************************************************************************************
90
91// #define USE_MEMORY_POOL_APPENDED_LISTS
92
98
110typedef bool (*CdiPoolItemOperatorFunction)(const void* context_ptr, void* item_ptr);
111
115typedef struct {
116 bool is_put;
118 const void* item_data_ptr;
120
128typedef void (*CdiPoolCallback)(const CdiPoolCbData* data_ptr);
129
130//*********************************************************************************************************************
131//******************************************* START OF PUBLIC FUNCTIONS ***********************************************
132//*********************************************************************************************************************
133
142CDI_INTERFACE uint32_t CdiPoolGetSizeNeeded(uint32_t item_count, uint32_t item_byte_size);
143
158CDI_INTERFACE bool CdiPoolCreate(const char* name_str, uint32_t item_count, uint32_t grow_count,
159 uint32_t max_grow_count, uint32_t item_byte_size, bool thread_safe,
160 CdiPoolHandle* ret_handle_ptr);
161
182CDI_INTERFACE bool CdiPoolCreateAndInitItems(const char* name_str, uint32_t item_count, uint32_t grow_count,
183 uint32_t max_grow_count, uint32_t item_byte_size, bool thread_safe,
184 CdiPoolHandle* ret_handle_ptr, CdiPoolItemOperatorFunction init_fn,
185 void* init_context_ptr);
186
211CDI_INTERFACE bool CdiPoolCreateUsingExistingBuffer(const char* name_str, uint32_t item_count, uint32_t item_byte_size,
212 bool thread_safe, void* buffer_ptr, uint32_t buffer_byte_size,
213 uint32_t* buffer_byte_size_needed_ptr,
214 CdiPoolHandle* ret_handle_ptr);
215
244CDI_INTERFACE bool CdiPoolCreateUsingExistingBufferAndInitItems(const char* name_str, uint32_t item_count,
245 uint32_t item_byte_size, bool thread_safe,
246 void* buffer_ptr, uint32_t buffer_byte_size,
247 uint32_t* buffer_byte_size_needed_ptr,
248 CdiPoolHandle* ret_handle_ptr,
250 void* init_context_ptr);
251
264CDI_INTERFACE bool CdiPoolPeekInUse(CdiPoolHandle handle, void** ret_item_ptr);
265
275CDI_INTERFACE bool CdiPoolGet(CdiPoolHandle handle, void** ret_item_ptr);
276
277#ifdef USE_MEMORY_POOL_APPENDED_LISTS
289CDI_INTERFACE bool CdiPoolGetAndAppend(CdiPoolHandle handle, void* existing_item_ptr, void** ret_item_ptr);
290#endif
291
298CDI_INTERFACE void CdiPoolPut(CdiPoolHandle handle, const void* item_ptr);
299
306
314CDI_INTERFACE const char* CdiPoolGetName(CdiPoolHandle handle);
315
324
333
342
356 const void* context_ptr);
357
366
373
380
381#endif // CDI_POOL_API_H__
CDI_INTERFACE bool CdiPoolCreateAndInitItems(const char *name_str, uint32_t item_count, uint32_t grow_count, uint32_t max_grow_count, uint32_t item_byte_size, bool thread_safe, CdiPoolHandle *ret_handle_ptr, CdiPoolItemOperatorFunction init_fn, void *init_context_ptr)
Definition pool.c:291
CDI_INTERFACE int CdiPoolGetFreeItemCount(CdiPoolHandle handle)
Definition pool.c:486
CDI_INTERFACE void CdiPoolPutAll(CdiPoolHandle handle)
Definition pool.c:456
CDI_INTERFACE bool CdiPoolCreateUsingExistingBuffer(const char *name_str, uint32_t item_count, uint32_t item_byte_size, bool thread_safe, void *buffer_ptr, uint32_t buffer_byte_size, uint32_t *buffer_byte_size_needed_ptr, CdiPoolHandle *ret_handle_ptr)
Definition pool.c:306
CDI_INTERFACE uint32_t CdiPoolGetItemSize(CdiPoolHandle handle)
Definition pool.c:479
CDI_INTERFACE bool CdiPoolForEachItem(CdiPoolHandle handle, CdiPoolItemOperatorFunction operator_function, const void *context_ptr)
Definition pool.c:508
void(* CdiPoolCallback)(const CdiPoolCbData *data_ptr)
Prototype of pool callback function.
Definition cdi_pool_api.h:128
CDI_INTERFACE bool CdiPoolPeekInUse(CdiPoolHandle handle, void **ret_item_ptr)
Definition pool.c:370
CDI_INTERFACE void CdiPoolPut(CdiPoolHandle handle, const void *item_ptr)
Definition pool.c:433
CDI_INTERFACE bool CdiPoolCreateUsingExistingBufferAndInitItems(const char *name_str, uint32_t item_count, uint32_t item_byte_size, bool thread_safe, void *buffer_ptr, uint32_t buffer_byte_size, uint32_t *buffer_byte_size_needed_ptr, CdiPoolHandle *ret_handle_ptr, CdiPoolItemOperatorFunction init_fn, void *init_context_ptr)
Definition pool.c:316
CDI_INTERFACE uint32_t CdiPoolGetSizeNeeded(uint32_t item_count, uint32_t item_byte_size)
Definition pool.c:276
CDI_INTERFACE void CdiPoolCallbackEnable(CdiPoolHandle handle, CdiPoolCallback cb_ptr)
Definition pool.c:530
CDI_INTERFACE bool CdiPoolCreate(const char *name_str, uint32_t item_count, uint32_t grow_count, uint32_t max_grow_count, uint32_t item_byte_size, bool thread_safe, CdiPoolHandle *ret_handle_ptr)
Definition pool.c:283
CDI_INTERFACE bool CdiPoolGet(CdiPoolHandle handle, void **ret_item_ptr)
Definition pool.c:393
struct CdiPoolState * CdiPoolHandle
Type used as the handle (pointer to an opaque structure) for a Memory Pool. Each handle represents a ...
Definition cdi_pool_api.h:97
bool(* CdiPoolItemOperatorFunction)(const void *context_ptr, void *item_ptr)
Definition cdi_pool_api.h:110
CDI_INTERFACE const char * CdiPoolGetName(CdiPoolHandle handle)
Definition pool.c:472
CDI_INTERFACE int CdiPoolGetTotalItemCount(CdiPoolHandle handle)
Get the total number of items in the pool.
Definition pool.c:497
CDI_INTERFACE void CdiPoolCallbackDisable(CdiPoolHandle handle)
Definition pool.c:537
CDI_INTERFACE void CdiPoolDestroy(CdiPoolHandle handle)
Definition pool.c:342
The declarations in this header file correspond to the definitions in cdi_utility_api....
#define CDI_INTERFACE
Specify C linkage when compiling as C++ and define API interface export for Windows.
Definition cdi_utility_api.h:34
Contains the state of a single pool get or put operation.
Definition cdi_pool_api.h:115
const void * item_data_ptr
Pointer to item data.
Definition cdi_pool_api.h:118
int num_entries
Current number of entries in the free_list.
Definition cdi_pool_api.h:117
bool is_put
True if pool get triggered the callback, otherwise a pool put triggered it.
Definition cdi_pool_api.h:116
This structure represents the current state of a memory pool.
Definition pool.c:46