design_pattern_for_c  V 1.00
memorypool.c File Reference
#include <elf.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include "memorypool.h"
Include dependency graph for memorypool.c:

Go to the source code of this file.

Data Structures

struct  maloc_data_t
 
struct  memorypool_t
 MemoryPool class member definition, detail is defined in C file. More...
 

Functions

index slide API
static int get_far_right_bit_index (uint64_t data)
 get right bit index More...
 
static int get_bit_digit_index_over_size (uint64_t size)
 get minimum of x, which 2^x > input_value More...
 
public API
MemoryPool mpool_create (size_t max_size, size_t max_cnt, int is_multithread, void(*constructor)(void *this, void *parameter), void *constructor_parameter)
 
void mpool_delete (MemoryPool this, void(*destructor)(void *))
 free MemoryPool class More...
 
void * mpool_get (MemoryPool this)
 get memory from pool More...
 
void * mpool_get_next_usedmem (MemoryPool this, void *ptr)
 get used memory More...
 
size_t mpool_get_usedcnt (MemoryPool this)
 get used cnt More...
 
void mpool_release (MemoryPool this, void *ptr)
 release memory to pool More...
 
void mpool_show (MemoryPool this)
 
#define MPOOL_LOCK(this)
 
#define MPOOL_UNLOCK   pthread_cleanup_pop(1);
 
typedef struct maloc_data_t malloc_data_t
 
typedef struct memorypool_t memorypool_t
 
static void mpool_list_push (MemoryPool this, malloc_data_t *data)
 
static void mpool_list_pull (MemoryPool this, malloc_data_t *data)
 
static void mpool_list_head (MemoryPool this, malloc_data_t *data)
 
static void * mpool_get_memory (MemoryPool this)
 
static void * mpool_get_next_memory (MemoryPool this, void *ptr)
 
static void mpool_unuse_memory (MemoryPool this, void *ptr)
 
static uint64_t mpool_get_buffer_place (MemoryPool this, uint8_t *buffer_list, void *ptr)
 
static int mpool_is_not_ptr_in_buf (MemoryPool this, void *ptr)
 
static void pthread_mutex_unlock_ (void *arg)
 
static void pthread_mutex_lock_ (MemoryPool this)
 

Macro Definition Documentation

◆ MPOOL_LOCK

#define MPOOL_LOCK (   this)
Value:
pthread_cleanup_push(pthread_mutex_unlock_, this->lock);
static void pthread_mutex_lock_(MemoryPool this)
Definition: memorypool.c:71
static void pthread_mutex_unlock_(void *arg)
Definition: memorypool.c:67

Definition at line 74 of file memorypool.c.

◆ MPOOL_UNLOCK

#define MPOOL_UNLOCK   pthread_cleanup_pop(1);

Definition at line 77 of file memorypool.c.

Typedef Documentation

◆ malloc_data_t

typedef struct maloc_data_t malloc_data_t

◆ memorypool_t

typedef struct memorypool_t memorypool_t

Function Documentation

◆ get_bit_digit_index_over_size()

static int get_bit_digit_index_over_size ( uint64_t  size)
static

get minimum of x, which 2^x > input_value

Definition at line 20 of file memorypool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_far_right_bit_index()

static int get_far_right_bit_index ( uint64_t  data)
static

get right bit index

Definition at line 11 of file memorypool.c.

Here is the caller graph for this function:

◆ mpool_create()

MemoryPool mpool_create ( size_t  max_size,
size_t  max_cnt,
int  is_multithread,
void(*)(void *this, void *parameter)  constructor,
void *  constructor_parameter 
)

Definition at line 170 of file memorypool.c.

Here is the call graph for this function:

◆ mpool_delete()

void mpool_delete ( MemoryPool  this,
void(*)(void *)  destructor 
)

free MemoryPool class

Parameters
[in]thisMemoryPool instance returned at mpool_malloc_new,
[in]destructorif you want to finialize memory
Returns
none

Definition at line 223 of file memorypool.c.

◆ mpool_get()

void* mpool_get ( MemoryPool  this)

get memory from pool

Parameters
[in]thisMemoryPool instance returned at mpool_malloc_new,
Return values
!=NULLallocated pointer
NULLmax_size of allocated memory
Note
If already get all allocated pointer, return NULL

Definition at line 236 of file memorypool.c.

Here is the call graph for this function:

◆ mpool_get_buffer_place()

static uint64_t mpool_get_buffer_place ( MemoryPool  this,
uint8_t *  buffer_list,
void *  ptr 
)
inlinestatic

Definition at line 157 of file memorypool.c.

Here is the caller graph for this function:

◆ mpool_get_memory()

static void * mpool_get_memory ( MemoryPool  this)
inlinestatic

Definition at line 116 of file memorypool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mpool_get_next_memory()

static void * mpool_get_next_memory ( MemoryPool  this,
void *  ptr 
)
inlinestatic

Definition at line 130 of file memorypool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mpool_get_next_usedmem()

void* mpool_get_next_usedmem ( MemoryPool  this,
void *  ptr 
)

get used memory

Parameters
[in]thisMemoryPool instance return,
[in]ptrused pointer
Return values
!=NULLget next
NULLthis pointer is end

Definition at line 245 of file memorypool.c.

Here is the call graph for this function:

◆ mpool_get_usedcnt()

size_t mpool_get_usedcnt ( MemoryPool  this)

get used cnt

Parameters
[in]thisMemoryPool instance return,
Returns
used count

Definition at line 257 of file memorypool.c.

◆ mpool_is_not_ptr_in_buf()

static int mpool_is_not_ptr_in_buf ( MemoryPool  this,
void *  ptr 
)
inlinestatic

Definition at line 162 of file memorypool.c.

Here is the caller graph for this function:

◆ mpool_list_head()

static void mpool_list_head ( MemoryPool  this,
malloc_data_t data 
)
inlinestatic

Definition at line 107 of file memorypool.c.

Here is the caller graph for this function:

◆ mpool_list_pull()

static void mpool_list_pull ( MemoryPool  this,
malloc_data_t data 
)
inlinestatic

Definition at line 94 of file memorypool.c.

Here is the caller graph for this function:

◆ mpool_list_push()

static void mpool_list_push ( MemoryPool  this,
malloc_data_t data 
)
inlinestatic

Definition at line 82 of file memorypool.c.

Here is the caller graph for this function:

◆ mpool_release()

void mpool_release ( MemoryPool  this,
void *  ptr 
)

release memory to pool

Parameters
[in]thisMemoryPool instance returned at mpool_malloc_new,
[in]ptrallocated pointer which get from mpool_malloc
Returns
none
Note
not initialize memory

Definition at line 266 of file memorypool.c.

Here is the call graph for this function:

◆ mpool_show()

void mpool_show ( MemoryPool  this)

Definition at line 279 of file memorypool.c.

◆ mpool_unuse_memory()

static void mpool_unuse_memory ( MemoryPool  this,
void *  ptr 
)
inlinestatic

Definition at line 147 of file memorypool.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pthread_mutex_lock_()

static void pthread_mutex_lock_ ( MemoryPool  this)
inlinestatic

Definition at line 71 of file memorypool.c.

◆ pthread_mutex_unlock_()

static void pthread_mutex_unlock_ ( void *  arg)
inlinestatic

Definition at line 67 of file memorypool.c.