diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:57:31 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2014-07-23 12:57:31 +0100 |
commit | 379055dbbb4af997b4d3ffb161d447872d7ca357 (patch) | |
tree | 3774553d470f93e12ddeb454aad9b3b607cf8918 /src/libutil/mem_pool.h | |
parent | 602ae7a0b7e215ba2677131b8fdc70abc156b3ca (diff) | |
download | rspamd-379055dbbb4af997b4d3ffb161d447872d7ca357.tar.gz rspamd-379055dbbb4af997b4d3ffb161d447872d7ca357.zip |
Unify style without sorting headers.
Diffstat (limited to 'src/libutil/mem_pool.h')
-rw-r--r-- | src/libutil/mem_pool.h | 108 |
1 files changed, 57 insertions, 51 deletions
diff --git a/src/libutil/mem_pool.h b/src/libutil/mem_pool.h index 17edf2fb2..2a8546ef0 100644 --- a/src/libutil/mem_pool.h +++ b/src/libutil/mem_pool.h @@ -19,10 +19,10 @@ struct f_str_s; #define MEM_ALIGNMENT sizeof(unsigned long) /* platform word */ #define align_ptr(p, a) \ - (guint8 *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1)) + (guint8 *) (((uintptr_t) (p) + ((uintptr_t) a - 1)) & ~((uintptr_t) a - 1)) -/** - * Destructor type definition +/** + * Destructor type definition */ typedef void (*rspamd_mempool_destruct_t)(void *ptr); @@ -39,10 +39,10 @@ typedef struct memory_pool_mutex_s { * Pool page structure */ struct _pool_chain { - guint8 *begin; /**< begin of pool chain block */ - guint8 *pos; /**< current start of free space in block */ - gsize len; /**< length of block */ - struct _pool_chain *next; /**< chain link */ + guint8 *begin; /**< begin of pool chain block */ + guint8 *pos; /**< current start of free space in block */ + gsize len; /**< length of block */ + struct _pool_chain *next; /**< chain link */ }; /** @@ -60,11 +60,11 @@ struct _pool_chain_shared { * Destructors list item structure */ struct _pool_destructors { - rspamd_mempool_destruct_t func; /**< pointer to destructor */ - void *data; /**< data to free */ - const gchar *function; /**< function from which this destructor was added */ - const gchar *loc; /**< line number */ - struct _pool_destructors *prev; /**< chain link */ + rspamd_mempool_destruct_t func; /**< pointer to destructor */ + void *data; /**< data to free */ + const gchar *function; /**< function from which this destructor was added */ + const gchar *loc; /**< line number */ + struct _pool_destructors *prev; /**< chain link */ }; /** @@ -72,51 +72,51 @@ struct _pool_destructors { */ struct rspamd_mutex_s; typedef struct memory_pool_s { - struct _pool_chain *cur_pool; /**< currently used page */ - struct _pool_chain *first_pool; /**< first page */ - struct _pool_chain *cur_pool_tmp; /**< currently used temporary page */ - struct _pool_chain *first_pool_tmp; /**< first temporary page */ - struct _pool_chain_shared *shared_pool; /**< shared chain */ - struct _pool_destructors *destructors; /**< destructors chain */ - GHashTable *variables; /**< private memory pool variables */ - struct rspamd_mutex_s *mtx; /**< threads lock */ + struct _pool_chain *cur_pool; /**< currently used page */ + struct _pool_chain *first_pool; /**< first page */ + struct _pool_chain *cur_pool_tmp; /**< currently used temporary page */ + struct _pool_chain *first_pool_tmp; /**< first temporary page */ + struct _pool_chain_shared *shared_pool; /**< shared chain */ + struct _pool_destructors *destructors; /**< destructors chain */ + GHashTable *variables; /**< private memory pool variables */ + struct rspamd_mutex_s *mtx; /**< threads lock */ } rspamd_mempool_t; /** * Statistics structure */ typedef struct memory_pool_stat_s { - gsize pools_allocated; /**< total number of allocated pools */ - gsize pools_freed; /**< number of freed pools */ - gsize bytes_allocated; /**< bytes that are allocated with pool allocator */ - gsize chunks_allocated; /**< number of chunks that are allocated */ - gsize shared_chunks_allocated; /**< shared chunks allocated */ - gsize chunks_freed; /**< chunks freed */ - gsize oversized_chunks; /**< oversized chunks */ + gsize pools_allocated; /**< total number of allocated pools */ + gsize pools_freed; /**< number of freed pools */ + gsize bytes_allocated; /**< bytes that are allocated with pool allocator */ + gsize chunks_allocated; /**< number of chunks that are allocated */ + gsize shared_chunks_allocated; /**< shared chunks allocated */ + gsize chunks_freed; /**< chunks freed */ + gsize oversized_chunks; /**< oversized chunks */ } rspamd_mempool_stat_t; /** * Rwlock for locking shared memory regions */ typedef struct memory_pool_rwlock_s { - rspamd_mempool_mutex_t *__r_lock; /**< read mutex (private) */ - rspamd_mempool_mutex_t *__w_lock; /**< write mutex (private) */ + rspamd_mempool_mutex_t *__r_lock; /**< read mutex (private) */ + rspamd_mempool_mutex_t *__w_lock; /**< write mutex (private) */ } rspamd_mempool_rwlock_t; /** - * Allocate new memory poll + * Allocate new memory poll * @param size size of pool's page * @return new memory pool object */ -rspamd_mempool_t* rspamd_mempool_new (gsize size); +rspamd_mempool_t * rspamd_mempool_new (gsize size); -/** +/** * Get memory from pool * @param pool memory pool object * @param size bytes to allocate * @return pointer to allocated object */ -void* rspamd_mempool_alloc (rspamd_mempool_t* pool, gsize size); +void * rspamd_mempool_alloc (rspamd_mempool_t * pool, gsize size); /** * Get memory from temporary pool @@ -124,7 +124,7 @@ void* rspamd_mempool_alloc (rspamd_mempool_t* pool, gsize size); * @param size bytes to allocate * @return pointer to allocated object */ -void* rspamd_mempool_alloc_tmp (rspamd_mempool_t* pool, gsize size); +void * rspamd_mempool_alloc_tmp (rspamd_mempool_t * pool, gsize size); /** * Get memory and set it to zero @@ -132,7 +132,7 @@ void* rspamd_mempool_alloc_tmp (rspamd_mempool_t* pool, gsize size); * @param size bytes to allocate * @return pointer to allocated object */ -void* rspamd_mempool_alloc0 (rspamd_mempool_t* pool, gsize size); +void * rspamd_mempool_alloc0 (rspamd_mempool_t * pool, gsize size); /** * Get memory and set it to zero @@ -140,12 +140,12 @@ void* rspamd_mempool_alloc0 (rspamd_mempool_t* pool, gsize size); * @param size bytes to allocate * @return pointer to allocated object */ -void* rspamd_mempool_alloc0_tmp (rspamd_mempool_t* pool, gsize size); +void * rspamd_mempool_alloc0_tmp (rspamd_mempool_t * pool, gsize size); /** * Cleanup temporary data in pool */ -void rspamd_mempool_cleanup_tmp (rspamd_mempool_t* pool); +void rspamd_mempool_cleanup_tmp (rspamd_mempool_t * pool); /** * Make a copy of string in pool @@ -153,7 +153,7 @@ void rspamd_mempool_cleanup_tmp (rspamd_mempool_t* pool); * @param src source string * @return pointer to newly created string that is copy of src */ -gchar* rspamd_mempool_strdup (rspamd_mempool_t* pool, const gchar *src); +gchar * rspamd_mempool_strdup (rspamd_mempool_t * pool, const gchar *src); /** * Make a copy of fixed string in pool as null terminated string @@ -161,16 +161,18 @@ gchar* rspamd_mempool_strdup (rspamd_mempool_t* pool, const gchar *src); * @param src source string * @return pointer to newly created string that is copy of src */ -gchar* rspamd_mempool_fstrdup (rspamd_mempool_t* pool, const struct f_str_s *src); +gchar * rspamd_mempool_fstrdup (rspamd_mempool_t * pool, + const struct f_str_s *src); /** * Allocate piece of shared memory * @param pool memory pool object * @param size bytes to allocate */ -void* rspamd_mempool_alloc_shared (rspamd_mempool_t* pool, gsize size); -void* rspamd_mempool_alloc0_shared (rspamd_mempool_t *pool, gsize size); -gchar* rspamd_mempool_strdup_shared (rspamd_mempool_t* pool, const gchar *src); +void * rspamd_mempool_alloc_shared (rspamd_mempool_t * pool, gsize size); +void * rspamd_mempool_alloc0_shared (rspamd_mempool_t *pool, gsize size); +gchar * rspamd_mempool_strdup_shared (rspamd_mempool_t * pool, + const gchar *src); /** * Lock chunk of shared memory in which pointer is placed @@ -192,12 +194,15 @@ void rspamd_mempool_lock_shared (rspamd_mempool_t *pool, void *pointer); * @param func pointer to function-destructor * @param data pointer to data that would be passed to destructor */ -void rspamd_mempool_add_destructor_full (rspamd_mempool_t *pool, rspamd_mempool_destruct_t func, void *data, - const gchar *function, const gchar *line); +void rspamd_mempool_add_destructor_full (rspamd_mempool_t *pool, + rspamd_mempool_destruct_t func, + void *data, + const gchar *function, + const gchar *line); /* Macros for common usage */ #define rspamd_mempool_add_destructor(pool, func, data) \ - rspamd_mempool_add_destructor_full(pool, func, data, G_STRFUNC, G_STRLOC) + rspamd_mempool_add_destructor_full (pool, func, data, G_STRFUNC, G_STRLOC) /** * Replace destructor callback to pool for specified pointer @@ -207,7 +212,7 @@ void rspamd_mempool_add_destructor_full (rspamd_mempool_t *pool, rspamd_mempool_ * @param new_data pointer to data that would be passed to destructor */ void rspamd_mempool_replace_destructor (rspamd_mempool_t *pool, - rspamd_mempool_destruct_t func, void *old_data, void *new_data); + rspamd_mempool_destruct_t func, void *old_data, void *new_data); /** * Delete pool, free all its chunks and call destructors chain @@ -215,12 +220,12 @@ void rspamd_mempool_replace_destructor (rspamd_mempool_t *pool, */ void rspamd_mempool_delete (rspamd_mempool_t *pool); -/** +/** * Get new mutex from pool (allocated in shared memory) * @param pool memory pool object * @return mutex object */ -rspamd_mempool_mutex_t* rspamd_mempool_get_mutex (rspamd_mempool_t *pool); +rspamd_mempool_mutex_t * rspamd_mempool_get_mutex (rspamd_mempool_t *pool); /** * Lock mutex @@ -239,7 +244,7 @@ void rspamd_mempool_unlock_mutex (rspamd_mempool_mutex_t *mutex); * @param pool memory pool object * @return rwlock object */ -rspamd_mempool_rwlock_t* rspamd_mempool_get_rwlock (rspamd_mempool_t *pool); +rspamd_mempool_rwlock_t * rspamd_mempool_get_rwlock (rspamd_mempool_t *pool); /** * Aquire read lock @@ -290,7 +295,7 @@ gsize rspamd_mempool_suggest_size (void); * @param destructor pointer to function-destructor */ void rspamd_mempool_set_variable (rspamd_mempool_t *pool, const gchar *name, - gpointer value, rspamd_mempool_destruct_t destructor); + gpointer value, rspamd_mempool_destruct_t destructor); /** * Get memory pool variable @@ -298,7 +303,8 @@ void rspamd_mempool_set_variable (rspamd_mempool_t *pool, const gchar *name, * @param name name of variable * @return NULL or pointer to variable data */ -gpointer rspamd_mempool_get_variable (rspamd_mempool_t *pool, const gchar *name); +gpointer rspamd_mempool_get_variable (rspamd_mempool_t *pool, + const gchar *name); #endif |