EM-ODP 4.4.0
Event Machine on ODP
Loading...
Searching...
No Matches
objpool.h File Reference
#include <stdint.h>
#include <event_machine/platform/env/environment.h>
#include "list.h"
Include dependency graph for objpool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  objpool_elem_t
 
union  objsubpool_t
 
struct  objpool_t
 

Macros

#define OBJSUBPOOLS_MAX   8
 

Functions

 COMPILE_TIME_ASSERT (2 *sizeof(objsubpool_t)==ENV_CACHE_LINE_SIZE, OBJSUBPOOL_T_SIZE_ERROR)
 
int objpool_init (objpool_t *const objpool, uint32_t nbr_subpools)
 
uint32_t objpool_subpools (const objpool_t *const objpool)
 
void objpool_add (objpool_t *const objpool, uint32_t subpool_idx, objpool_elem_t *const elem)
 
objpool_elem_tobjpool_rem (objpool_t *const objpool, uint32_t subpool_idx)
 
int objpool_rem_elem (objpool_t *const objpool, objpool_elem_t *const elem)
 

Detailed Description

Simple object pool for managing collections of objects.

Objects stored in the pool must embed an objpool_elem_t member that is used internally to link the object into the pool. The pool is divided into independently locked subpools to reduce contention in multithreaded use.

Definition in file objpool.h.

Macro Definition Documentation

◆ OBJSUBPOOLS_MAX

#define OBJSUBPOOLS_MAX   8

Maximum number of subpools in an object pool.

This compile-time limit is set to 8 as a balance between reducing lock contention (more subpools) and keeping the objpool_t structure small enough to preserve cache locality. Increasing this value is possible if a particular workload benefits from more independently locked subpools, but doing so will grow the size of objpool_t proportionally.

Definition at line 62 of file objpool.h.

Function Documentation

◆ objpool_add()

void objpool_add ( objpool_t *const  objpool,
uint32_t  subpool_idx,
objpool_elem_t *const  elem 
)

Add an object to the object pool.

Parameters
objpoolObject pool.
subpool_idxIndex of the subpool to add the element to (modulo nbr_subpools).
elemObject pool element embedded in the object to add.

Definition at line 63 of file objpool.c.

◆ objpool_init()

int objpool_init ( objpool_t *const  objpool,
uint32_t  nbr_subpools 
)

Initialize an object pool.

Parameters
objpoolObject pool to initialize.
nbr_subpoolsNumber of subpools, clamped to OBJSUBPOOLS_MAX.
Returns
0 on success.
Return values
<0on failure (invalid parameters).

Definition at line 38 of file objpool.c.

◆ objpool_rem()

objpool_elem_t * objpool_rem ( objpool_t *const  objpool,
uint32_t  subpool_idx 
)

Remove and return an object from the object pool.

Tries the given subpool first, then searches the remaining subpools round-robin until a free object is found.

Parameters
objpoolObject pool.
subpool_idxPreferred subpool index to remove from first.
Returns
Pointer to the removed element, or NULL if the pool is empty.

Definition at line 78 of file objpool.c.

◆ objpool_rem_elem()

int objpool_rem_elem ( objpool_t *const  objpool,
objpool_elem_t *const  elem 
)

Remove a specific object from the object pool.

Parameters
objpoolObject pool.
elemObject pool element to remove.
Returns
0 on success, -1 if the element was not in the pool.

Definition at line 104 of file objpool.c.

◆ objpool_subpools()

uint32_t objpool_subpools ( const objpool_t *const  objpool)

Return the number of subpools in use by the object pool.

Parameters
objpoolObject pool.
Returns
Number of subpools.

Definition at line 58 of file objpool.c.