mem0pool.h 2.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/******************************************************
The lowest-level memory management

(c) 1994, 1995 Innobase Oy

Created 6/9/1994 Heikki Tuuri
*******************************************************/

#ifndef mem0pool_h
#define mem0pool_h

#include "univ.i"
#include "os0file.h"
14
#include "ut0lst.h"
15 16 17 18 19 20 21

typedef struct mem_area_struct	mem_area_t;
typedef struct mem_pool_struct	mem_pool_t;

/* The common memory pool */
extern mem_pool_t*	mem_comm_pool;

22 23 24 25 26 27
/* Memory area header */

struct mem_area_struct{
	ulint		size_and_free;	/* memory area size is obtained by
					anding with ~MEM_AREA_FREE; area in
					a free list if ANDing with
28
					MEM_AREA_FREE results in nonzero */
29 30 31 32
	UT_LIST_NODE_T(mem_area_t)
			free_list;	/* free list node */
};

33
/* Each memory area takes this many extra bytes for control information */
34
#define MEM_AREA_EXTRA_SIZE	(ut_calc_align(sizeof(struct mem_area_struct),\
35
			UNIV_MEM_ALIGNMENT))
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

/************************************************************************
Creates a memory pool. */

mem_pool_t*
mem_pool_create(
/*============*/
			/* out: memory pool */
	ulint	size);	/* in: pool size in bytes */
/************************************************************************
Allocates memory from a pool. NOTE: This low-level function should only be
used in mem0mem.*! */

void*
mem_area_alloc(
/*===========*/
				/* out, own: allocated memory buffer */
	ulint		size,	/* in: allocated size in bytes; for optimum
				space usage, the size should be a power of 2
				minus MEM_AREA_EXTRA_SIZE */
	mem_pool_t*	pool);	/* in: memory pool */
/************************************************************************
Frees memory to a pool. */

void
mem_area_free(
/*==========*/
	void*		ptr,	/* in, own: pointer to allocated memory
				buffer */
	mem_pool_t*	pool);	/* in: memory pool */
/************************************************************************
Returns the amount of reserved memory. */

ulint
mem_pool_get_reserved(
/*==================*/
				/* out: reserved mmeory in bytes */
	mem_pool_t*	pool);	/* in: memory pool */
/************************************************************************
unknown's avatar
unknown committed
75 76 77 78 79 80 81 82 83 84 85 86
Reserves the mem pool mutex. */

void
mem_pool_mutex_enter(void);
/*======================*/
/************************************************************************
Releases the mem pool mutex. */

void
mem_pool_mutex_exit(void);
/*=====================*/
/************************************************************************
87 88 89 90 91 92 93 94 95 96 97 98 99
Validates a memory pool. */

ibool
mem_pool_validate(
/*==============*/
				/* out: TRUE if ok */
	mem_pool_t*	pool);	/* in: memory pool */
/************************************************************************
Prints info of a memory pool. */

void
mem_pool_print_info(
/*================*/
100
	FILE*		outfile,/* in: output file to write to */
101
	mem_pool_t*	pool);	/* in: memory pool */
102

103 104 105 106 107

#ifndef UNIV_NONINL
#include "mem0pool.ic"
#endif

108
#endif