Modbus Vault v1.0
Loading...
Searching...
No Matches
slab_pool.c File Reference

Implementation of the slab pool. More...

#include "slab_pool.h"
#include "esp_err.h"
#include "esp_log.h"
#include <string.h>
Include dependency graph for slab_pool.c:

Data Structures

struct  slab_node_t
 Slab Pool internal node structure. More...
 

Functions

static void pool_lock_take (void)
 Lock pool.
 
static void pool_lock_give (void)
 Unlock pool.
 
esp_err_t slab_pool_init (void)
 Initialize slab pool.
 
slab_pool_tslab_pool_alloc (void)
 Allocate a slab from pool.
 
void slab_pool_free (slab_pool_t *slab_ptr)
 Return slab to pool.
 
void slab_pool_deinit (void)
 Deinitialize slab pool.
 

Variables

static const char * TAG = "SLAB_POOL"
 
static slab_node_t pool [SLAB_POOL_SIZE]
 
static slab_node_tfree_list = NULL
 
static SemaphoreHandle_t pool_lock = NULL
 
static bool is_slab_pool_initialized = false
 

Detailed Description

Implementation of the slab pool.

  • Uses a static pool of slabs
  • Manage available slabs using singly linked list with a lock for mutual access
  • On slab alloc returns list head if available
  • On slab free make the returned slab the new head

Function Documentation

◆ slab_pool_alloc()

slab_pool_t * slab_pool_alloc ( void  )

Allocate a slab from pool.

Returns
slab_pool_t* pointer to slab on success otherwise NULL
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slab_pool_free()

void slab_pool_free ( slab_pool_t slab_ptr)

Return slab to pool.

Parameters
slab_ptrPointer to slab structure
Here is the call graph for this function:
Here is the caller graph for this function:

◆ slab_pool_init()

esp_err_t slab_pool_init ( void  )

Initialize slab pool.

Returns
esp_err_t Initialize result
Return values
ESP_OKInitialize success
ESP_ERR_NO_MEMNo available memory for resource allocation
ESP_ERR_INVALID_STATEAlready initialized
Here is the caller graph for this function:

Variable Documentation

◆ free_list

slab_node_t* free_list = NULL
static

Slab pool list head

◆ is_slab_pool_initialized

bool is_slab_pool_initialized = false
static

Slab pool initialization state

◆ pool

Slab pool list

◆ pool_lock

SemaphoreHandle_t pool_lock = NULL
static

Slab pool list lock

◆ TAG

const char* TAG = "SLAB_POOL"
static

Slab pool TAG name