#ifndef BASE_POOL_PVT_H
#define BASE_POOL_PVT_H
#ifndef BASE_POOL_H
#include "pool.h"
#include <inttypes.h>
#include <cx/allocator.h>
#endif
#ifdef DEBUG
#define PER_POOL_STATISTICS
#endif
#ifdef DEBUG
#define POOL_ZERO_DEBUG 0xa
#endif
#define DEFAULT_BLOCK_SIZE (
32 *
1024)
#define DEFAULT_RETENTION_SIZE (
DEFAULT_BLOCK_SIZE *
2)
#define DEFAULT_RETENTION_NUM 2
#define WORD_SIZE 8
#undef ALIGN
#define ALIGN(x) ( (x +
WORD_SIZE-
1) & (~(
WORD_SIZE-
1)) )
#ifdef PER_POOL_STATISTICS
typedef struct pool_stats_t pool_stats_t;
struct pool_stats_t {
PRUint32 poolId;
PRUint32 maxAlloc;
PRUint32 allocCnt;
PRUint32 freeCnt;
PRUint32 blkAlloc;
PRUint32 blkFree;
PRThread *thread;
PRTime created;
};
#endif
typedef struct pool_config_t pool_config_t;
struct pool_config_t {
int32_t block_size;
int32_t retain_size;
int32_t retain_num;
};
#define POOL_CONFIG_INIT { \
DEFAULT_BLOCK_SIZE, \
DEFAULT_RETENTION_SIZE, \
DEFAULT_RETENTION_NUM, \
}
typedef struct block_t block_t;
struct block_t {
char *data;
char *start;
char *end;
block_t *next;
};
#define POOL_PTR_IN_BLOCK(blk, ptr) \
(((
char *)(ptr) < (blk)->end) && ((
char *)(ptr) >= (blk)->data))
typedef struct pool_t pool_t;
struct pool_t {
CxAllocator allocator;
block_t *curr_block;
block_t *used_blocks;
block_t *free_blocks;
int32_t free_size;
int32_t free_num;
size_t size;
pool_t *next;
#ifdef PER_POOL_STATISTICS
pool_stats_t stats;
#endif
};
typedef struct pool_global_stats_t pool_global_stats_t;
struct pool_global_stats_t {
pool_t *poolList;
int32_t createCnt;
int32_t destroyCnt;
#ifdef POOL_GLOBAL_STATISTICS
PRUint32 blkAlloc;
PRUint32 blkFree;
#endif
};
NSAPI_PUBLIC pool_config_t *pool_getConfig(
void);
NSAPI_PUBLIC pool_global_stats_t *pool_getGlobalStats(
void);
#ifdef PER_POOL_STATISTICS
NSAPI_PUBLIC pool_stats_t *pool_getPoolStats(
pool_handle_t *pool_handle);
#endif
#endif