43 lines
714 B
C
43 lines
714 B
C
|
#ifndef MPOOL_H
|
|||
|
#define MPOOL_H
|
|||
|
|
|||
|
#include <stdlib.h>
|
|||
|
|
|||
|
#include "const.h"
|
|||
|
|
|||
|
struct mpool_block_s {
|
|||
|
struct mpool_block_s *next;
|
|||
|
struct mpool_block_s *prev;
|
|||
|
char obj;
|
|||
|
};
|
|||
|
|
|||
|
struct mpool_s {
|
|||
|
size_t nblocks;
|
|||
|
void *pool;
|
|||
|
struct mpool_block_s *free_pool;
|
|||
|
struct mpool_block_s *busy_pool;
|
|||
|
};
|
|||
|
|
|||
|
/*
|
|||
|
* инициализация пула
|
|||
|
*/
|
|||
|
void mpool_init(struct mpool_s *bp, size_t nblocks, size_t mpool_block_size);
|
|||
|
|
|||
|
/*
|
|||
|
* уничтожение пула
|
|||
|
*/
|
|||
|
void mpool_destroy(struct mpool_s *bp);
|
|||
|
|
|||
|
/*
|
|||
|
* выдача блока из пула
|
|||
|
*/
|
|||
|
void *mpool_alloc(struct mpool_s *bp);
|
|||
|
|
|||
|
/*
|
|||
|
* возвращение блока в пул
|
|||
|
*/
|
|||
|
void mpool_free(struct mpool_s *bp, void *p);
|
|||
|
|
|||
|
#endif // MPOOL_H
|
|||
|
|