<commit_before>#ifndef FT_MEMPOOL_POOL_H_
#define FT_MEMPOOL_POOL_H_

/*
Fixed-size block memory pool.
See https://en.wikipedia.org/wiki/Memory_pool
*/

struct ft_pool
{
	struct ft_poolzone * zones;
	ft_pool_alloc_fnct alloc_fnct;
};

bool ft_pool_init(struct ft_pool *); // Context can be null
void ft_pool_fini(struct ft_pool *);

void ft_pool_set_alloc(struct ft_pool *, ft_pool_alloc_fnct alloc_fnct);

size_t ft_pool_count_available_frames(struct ft_pool *);
size_t ft_pool_count_zones(struct ft_pool *);

struct ft_frame * _ft_pool_borrow_real(struct ft_pool *, uint64_t frame_type, const char * file, unsigned int line);
#define ft_pool_borrow(pool, frame_type) _ft_pool_borrow_real(pool, frame_type, __FILE__, __LINE__)

// Following function requires access to pool object internals
// and for this reason it is here and not with ft_frame object
static inline void ft_frame_return(struct ft_frame * frame)
{
	int rc;
	struct ft_poolzone * zone = frame->zone;

	FT_TRACE(FT_TRACE_ID_MEMPOOL, "BEGIN f:%p", frame);

	frame->type = FT_FRAME_TYPE_FREE;

	frame->next = zone->available_frames;
	zone->available_frames = frame;

	zone->frames_used -= 1;<commit_msg>Reset of the allocation info when the frame returned.<commit_after>#ifndef FT_MEMPOOL_POOL_H_
#define FT_MEMPOOL_POOL_H_

/*
Fixed-size block memory pool.
See https://en.wikipedia.org/wiki/Memory_pool
*/

struct ft_pool
{
	struct ft_poolzone * zones;
	ft_pool_alloc_fnct alloc_fnct;
};

bool ft_pool_init(struct ft_pool *); // Context can be null
void ft_pool_fini(struct ft_pool *);

void ft_pool_set_alloc(struct ft_pool *, ft_pool_alloc_fnct alloc_fnct);

size_t ft_pool_count_available_frames(struct ft_pool *);
size_t ft_pool_count_zones(struct ft_pool *);

struct ft_frame * _ft_pool_borrow_real(struct ft_pool *, uint64_t frame_type, const char * file, unsigned int line);
#define ft_pool_borrow(pool, frame_type) _ft_pool_borrow_real(pool, frame_type, __FILE__, __LINE__)

// Following function requires access to pool object internals
// and for this reason it is here and not with ft_frame object
static inline void ft_frame_return(struct ft_frame * frame)
{
	int rc;
	struct ft_poolzone * zone = frame->zone;

	FT_TRACE(FT_TRACE_ID_MEMPOOL, "BEGIN f:%p", frame);

	frame->type = FT_FRAME_TYPE_FREE;

	frame->next = zone->available_frames;
	zone->available_frames = frame;

	frame->borrowed_by_file = NULL;
	frame->borrowed_by_line = -1;

	zone->frames_used -= 1;
{'fraction_non_alphanumeric': 0.09176566980745596, 'fraction_numerical': 0.0028676771814829987, 'mean_word_length': 5.859550561797753, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5752226', 'n_tokens_mistral': 889, 'n_tokens_neox': 858, 'n_words': 213}