diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-01-27 19:15:51 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-01-27 19:15:51 +0300 |
commit | a450d0faa8851a7df8dbb52788f99fe216f57c3d (patch) | |
tree | ed2f45a6fd083e7e3b833bbdd576874d122c5f69 /src/mem_pool.h | |
parent | ec5b7a84cfd158b8b6b5714b47c48028a9c29a6a (diff) | |
download | rspamd-a450d0faa8851a7df8dbb52788f99fe216f57c3d.tar.gz rspamd-a450d0faa8851a7df8dbb52788f99fe216f57c3d.zip |
* Add new hash for storing hash data in shared memory
* Add rwlocks implementation (primitive) in memory pool library
Diffstat (limited to 'src/mem_pool.h')
-rw-r--r-- | src/mem_pool.h | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/mem_pool.h b/src/mem_pool.h index 22388df70..cd1af2e77 100644 --- a/src/mem_pool.h +++ b/src/mem_pool.h @@ -41,19 +41,44 @@ typedef struct memory_pool_stat_s { size_t chunks_freed; } memory_pool_stat_t; +typedef struct memory_pool_rwlock_s { + gint *__r_lock; + gint *__w_lock; +} memory_pool_rwlock_t; + +/* Allocate new memory poll */ memory_pool_t* memory_pool_new (size_t size); + +/* Get memory from pool */ void* memory_pool_alloc (memory_pool_t* pool, size_t size); +/* Get memory and set it to zero */ void* memory_pool_alloc0 (memory_pool_t* pool, size_t size); +/* Make a copy of string in pool */ char* memory_pool_strdup (memory_pool_t* pool, const char *src); -void memory_pool_add_destructor (memory_pool_t *pool, pool_destruct_func func, void *data); + +/* Allocate piece of shared memory */ void* memory_pool_alloc_shared (memory_pool_t *pool, size_t size); +/* Lock and unlock chunk of shared memory in which pointer is placed */ void memory_pool_lock_shared (memory_pool_t *pool, void *pointer); void memory_pool_unlock_shared (memory_pool_t *pool, void *pointer); + +/* Add destructor callback to pool */ +void memory_pool_add_destructor (memory_pool_t *pool, pool_destruct_func func, void *data); +/* Delete pool, free all its chunks and call destructors chain */ void memory_pool_delete (memory_pool_t *pool); + +/* Mutexes operations */ gint* memory_pool_get_mutex (memory_pool_t *pool); void memory_pool_lock_mutex (gint *mutex); void memory_pool_unlock_mutex (gint *mutex); +/* Simple rwlock implementation */ +memory_pool_rwlock_t* memory_pool_get_rwlock (memory_pool_t *pool); +void memory_pool_rlock_rwlock (memory_pool_rwlock_t *lock); +void memory_pool_wlock_rwlock (memory_pool_rwlock_t *lock); +void memory_pool_runlock_rwlock (memory_pool_rwlock_t *lock); +void memory_pool_wunlock_rwlock (memory_pool_rwlock_t *lock); + void memory_pool_stat (memory_pool_stat_t *st); /* Get optimal pool size based on page size for this system */ |