FS-10167: Rewrote the ks_pool allocator, no longer uses paging or internal block allocation, but still retains reference counting and auto cleanup callbacks, should be much more efficient now on windows than the original mmap approach, and all tests now run successfully!

This commit is contained in:
Shane Bryldt 2017-04-11 14:43:00 -06:00
parent aaa26c6d09
commit ea0dc132a3
17 changed files with 526 additions and 1679 deletions

View File

@ -312,7 +312,7 @@ KS_DECLARE(void) blade_connection_disconnect(blade_connection_t *bc)
{
ks_assert(bc);
if (bc->state != BLADE_CONNECTION_STATE_DETACH && bc->state != BLADE_CONNECTION_STATE_DISCONNECT) {
if (bc->state != BLADE_CONNECTION_STATE_DETACH && bc->state != BLADE_CONNECTION_STATE_DISCONNECT && bc->state != BLADE_CONNECTION_STATE_CLEANUP) {
ks_log(KS_LOG_DEBUG, "Connection (%s) disconnecting\n", bc->id);
blade_connection_state_set(bc, BLADE_CONNECTION_STATE_DETACH);
}
@ -453,7 +453,7 @@ ks_status_t blade_connection_state_on_attach(blade_connection_t *bc)
callback = blade_connection_state_callback_lookup(bc, BLADE_CONNECTION_STATE_ATTACH);
if (callback) hook = callback(bc, BLADE_CONNECTION_STATE_CONDITION_POST);
if (hook == BLADE_CONNECTION_STATE_HOOK_DISCONNECT) blade_connection_disconnect(bc);
if (hook == BLADE_CONNECTION_STATE_HOOK_DISCONNECT) blade_connection_disconnect(bc);
else if (hook == BLADE_CONNECTION_STATE_HOOK_SUCCESS) {
// @todo this is adding a second lock, since we keep it locked in the callback to allow finishing, we don't want get locking here...
// or just try unlocking twice to confirm...

View File

@ -77,7 +77,7 @@ KS_DECLARE(ks_status_t) blade_datastore_create(blade_datastore_t **bdsP, ks_pool
ks_assert(bdsP);
ks_assert(pool);
ks_assert(tpool);
//ks_assert(tpool);
bds = ks_pool_alloc(pool, sizeof(*bds));
bds->pool = pool;

View File

@ -869,7 +869,7 @@ blade_connection_state_hook_t blade_transport_wss_on_state_disconnect(blade_conn
list_delete(&bt_wss->module->connected, bc);
if (bt_wss_init) blade_transport_wss_init_destroy(&bt_wss_init);
if (bt_wss) blade_transport_wss_destroy(&bt_wss);
if (bt_wss) blade_transport_wss_destroy(&bt_wss); // @TODO: Scream at this very loudly until I feel better for it wasting 2 days to track down, and then fix the issue it's causing
return BLADE_CONNECTION_STATE_HOOK_SUCCESS;
}
@ -1092,6 +1092,8 @@ blade_connection_state_hook_t blade_transport_wss_on_state_attach_inbound(blade_
// behaviour to simply go as far as assigning a session to the connection and let the system handle the rest
if (json_req) cJSON_Delete(json_req);
if (json_res) cJSON_Delete(json_res);
return ret;
}
@ -1223,6 +1225,7 @@ blade_connection_state_hook_t blade_transport_wss_on_state_attach_outbound(blade
done:
if (json_req) cJSON_Delete(json_req);
if (json_res) cJSON_Delete(json_res);
return ret;
}
@ -1261,15 +1264,15 @@ blade_connection_state_hook_t blade_transport_wss_on_state_ready_outbound(blade_
if (condition == BLADE_CONNECTION_STATE_CONDITION_PRE) {
blade_session_t *bs = NULL;
cJSON *req = NULL;
//cJSON *req = NULL;
ks_log(KS_LOG_DEBUG, "State Callback: %d\n", (int32_t)condition);
bs = blade_handle_sessions_get(blade_connection_handle_get(bc), blade_connection_session_get(bc));
ks_assert(bs);
blade_rpc_request_create(blade_connection_pool_get(bc), &req, NULL, NULL, "blade.test.echo");
blade_session_send(bs, req, blade_test_echo_response_handler);
//blade_rpc_request_create(blade_connection_pool_get(bc), &req, NULL, NULL, "blade.test.echo");
//blade_session_send(bs, req, blade_test_echo_response_handler);
blade_session_read_unlock(bs);
}

View File

@ -159,6 +159,7 @@ KS_DECLARE(ks_status_t) blade_session_shutdown(blade_session_t *bs)
if (bs->state_thread) {
bs->shutdown = KS_TRUE;
ks_thread_join(bs->state_thread);
printf("FREEING SESSION THREAD %p\n", (void *)bs->state_thread);
ks_pool_free(bs->pool, &bs->state_thread);
bs->shutdown = KS_FALSE;
}

View File

@ -122,10 +122,10 @@ void on_blade_session_state_callback(blade_session_t *bs, blade_session_state_co
if (condition == BLADE_SESSION_STATE_CONDITION_PRE) {
ks_log(KS_LOG_DEBUG, "Blade Session State Changed: %s, %d\n", blade_session_id_get(bs), state);
if (state == BLADE_SESSION_STATE_READY) {
cJSON *req = NULL;
blade_rpc_request_create(blade_session_pool_get(bs), &req, NULL, NULL, "blade.chat.join");
blade_session_send(bs, req, on_blade_chat_join_response);
cJSON_Delete(req);
//cJSON *req = NULL;
//blade_rpc_request_create(blade_session_pool_get(bs), &req, NULL, NULL, "blade.chat.join");
//blade_session_send(bs, req, on_blade_chat_join_response);
//cJSON_Delete(req);
}
}
}

View File

@ -72,13 +72,13 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
blade_module_chat_on_load(&mod_chat, bh);
blade_module_chat_on_startup(mod_chat, config_blade);
//blade_module_chat_on_load(&mod_chat, bh);
//blade_module_chat_on_startup(mod_chat, config_blade);
loop(bh);
blade_module_chat_on_shutdown(mod_chat);
blade_module_chat_on_unload(mod_chat);
//blade_module_chat_on_shutdown(mod_chat);
//blade_module_chat_on_unload(mod_chat);
blade_module_wss_on_shutdown(mod_wss);

View File

@ -72,16 +72,22 @@ _Check_return_ static __inline int _zstr(_In_opt_z_ const char *s)
#define ks_set_string(_x, _y) ks_copy_string(_x, _y, sizeof(_x))
#define ks_safe_free(_x) if (_x) free(_x); _x = NULL
#define end_of(_s) *(*_s == '\0' ? _s : _s + strlen(_s) - 1)
#define ks_test_flag(obj, flag) ((obj)->flags & flag)
#define ks_set_flag(obj, flag) (obj)->flags |= (flag)
#define ks_clear_flag(obj, flag) (obj)->flags &= ~(flag)
#define ks_recv(_h) ks_recv_event(_h, 0, NULL)
#define ks_recv_timed(_h, _ms) ks_recv_event_timed(_h, _ms, 0, NULL)
/*
* bitflag tools
*/
#define BIT_FLAG(x) (1 << (x))
#define BIT_SET(v,f) ((v) |= (f))
#define BIT_CLEAR(v,f) ((v) &= ~(f))
#define BIT_IS_SET(v,f) ((v) & (f))
#define BIT_TOGGLE(v,f) ((v) ^= (f))
KS_DECLARE(ks_status_t) ks_init(void);
KS_DECLARE(ks_status_t) ks_shutdown(void);
KS_DECLARE(ks_pool_t *) ks_global_pool(void);
KS_DECLARE(ks_status_t) ks_global_set_cleanup(ks_pool_cleanup_fn_t fn, void *arg);
KS_DECLARE(ks_status_t) ks_global_set_cleanup(ks_pool_cleanup_callback_t callback, void *arg);
KS_DECLARE(int) ks_vasprintf(char **ret, const char *fmt, va_list ap);
//KS_DECLARE_DATA extern ks_logger_t ks_logger;

View File

@ -33,29 +33,7 @@ KS_BEGIN_EXTERN_C
*/
typedef enum {
KS_POOL_FLAG_DEFAULT = 0,
KS_POOL_FLAG_BEST_FIT = (1 << 0),
KS_POOL_FLAG_NO_ASSERT = (1 << 1),
KS_POOL_FLAG_NO_ZERO = (1 << 2),
/*
* Choose a best fit algorithm not first fit. This takes more CPU
* time but will result in a tighter heap.
*/
KS_POOL_FLAG_HEAVY_PACKING = (1 << 1)
/*
* This enables very heavy packing at the possible expense of CPU.
* This affects a number of parts of the library.
*
* By default the 1st page of memory is reserved for the main ks_pool
* structure. This flag will cause the rest of the 1st block to be
* available for use as user memory.
*
* By default the library looks through the memory when freed looking
* for a magic value. There is an internal max size that it will look
* and then it will give up. This flag forces it to look until it
* finds it.
*/
KS_POOL_FLAG_DEFAULT = 0
} ks_pool_flag_t;
/*
@ -83,7 +61,7 @@ typedef enum {
*
* ARGUMENT:
*
* mp_p -> Associated ks_pool address.
* pool -> Associated ks_pool address.
*
* func_id -> Integer function ID which identifies which ks_pool
* function is being called.
@ -102,10 +80,10 @@ typedef enum {
* old_byte_size -> Optionally specified old byte size. For
* ks_pool_resize only.
*/
typedef void (*ks_pool_log_func_t) (const void *mp_p,
typedef void (*ks_pool_log_func_t) (const void *pool,
const int func_id,
const unsigned long byte_size,
const unsigned long ele_n, const void *old_addr, const void *new_addr, const unsigned long old_byte_size);
const ks_size_t byte_size,
const ks_size_t ele_n, const void *old_addr, const void *new_addr, const ks_size_t old_byte_size);
/*
* ks_pool_t *ks_pool_open
@ -144,10 +122,10 @@ KS_DECLARE(ks_status_t) ks_pool_open(ks_pool_t **poolP);
*
* ARGUMENTS:
*
* mp_pp <-> Pointer to pointer of our memory pool.
* poolP <-> Pointer to pointer of our memory pool.
*/
KS_DECLARE(ks_status_t) ks_pool_close(ks_pool_t **mp_pP);
KS_DECLARE(ks_status_t) ks_pool_close(ks_pool_t **poolP);
/*
* int ks_pool_clear
@ -164,10 +142,10 @@ KS_DECLARE(ks_status_t) ks_pool_close(ks_pool_t **mp_pP);
*
* ARGUMENTS:
*
* mp_p <-> Pointer to our memory pool.
* pool <-> Pointer to our memory pool.
*/
KS_DECLARE(ks_status_t) ks_pool_clear(ks_pool_t *mp_p);
KS_DECLARE(ks_status_t) ks_pool_clear(ks_pool_t *pool);
/*
* void *ks_pool_alloc
@ -184,13 +162,12 @@ KS_DECLARE(ks_status_t) ks_pool_clear(ks_pool_t *mp_p);
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool. If NULL then it will do a
* normal malloc.
* pool -> Pointer to the memory pool.
*
* byte_size -> Number of bytes to allocate in the pool. Must be >0.
* size -> Number of bytes to allocate in the pool. Must be >0.
*
*/
KS_DECLARE(void *) ks_pool_alloc(ks_pool_t *mp_p, const unsigned long byte_size);
KS_DECLARE(void *) ks_pool_alloc(ks_pool_t *pool, const ks_size_t size);
/*
* void *ks_pool_alloc_ex
@ -207,15 +184,14 @@ KS_DECLARE(void *) ks_pool_alloc(ks_pool_t *mp_p, const unsigned long byte_size)
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool. If NULL then it will do a
* normal malloc.
* pool -> Pointer to the memory pool.
*
* byte_size -> Number of bytes to allocate in the pool. Must be >0.
* size -> Number of bytes to allocate in the pool. Must be >0.
*
* error_p <- Pointer to integer which, if not NULL, will be set with
* a ks_pool error code.
*/
KS_DECLARE(void *) ks_pool_alloc_ex(ks_pool_t *mp_p, const unsigned long byte_size, ks_status_t *error_p);
KS_DECLARE(void *) ks_pool_alloc_ex(ks_pool_t *pool, const ks_size_t size, ks_status_t *error_p);
/*
* void *ks_pool_calloc
@ -233,15 +209,14 @@ KS_DECLARE(void *) ks_pool_alloc_ex(ks_pool_t *mp_p, const unsigned long byte_si
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool. If NULL then it will do a
* normal calloc.
* pool -> Pointer to the memory pool.
*
* ele_n -> Number of elements to allocate.
*
* ele_size -> Number of bytes per element being allocated.
*
*/
KS_DECLARE(void *) ks_pool_calloc(ks_pool_t *mp_p, const unsigned long ele_n, const unsigned long ele_size);
KS_DECLARE(void *) ks_pool_calloc(ks_pool_t *pool, const ks_size_t ele_n, const ks_size_t ele_size);
/*
* void *ks_pool_calloc_ex
@ -259,8 +234,7 @@ KS_DECLARE(void *) ks_pool_calloc(ks_pool_t *mp_p, const unsigned long ele_n, co
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool. If NULL then it will do a
* normal calloc.
* pool -> Pointer to the memory pool.
*
* ele_n -> Number of elements to allocate.
*
@ -269,7 +243,7 @@ KS_DECLARE(void *) ks_pool_calloc(ks_pool_t *mp_p, const unsigned long ele_n, co
* error_p <- Pointer to integer which, if not NULL, will be set with
* a ks_pool error code.
*/
KS_DECLARE(void *) ks_pool_calloc_ex(ks_pool_t *mp_p, const unsigned long ele_n, const unsigned long ele_size, ks_status_t *error_p);
KS_DECLARE(void *) ks_pool_calloc_ex(ks_pool_t *pool, const ks_size_t ele_n, const ks_size_t ele_size, ks_status_t *error_p);
/*
* int ks_pool_free
@ -286,14 +260,14 @@ KS_DECLARE(void *) ks_pool_calloc_ex(ks_pool_t *mp_p, const unsigned long ele_n,
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool. If NULL then it will do a
* pool -> Pointer to the memory pool. If NULL then it will do a
* normal free.
*
* addr <-> Address to free.
*
*/
KS_DECLARE(ks_status_t) ks_pool_free_ex(ks_pool_t *mp_p, void **addrP);
KS_DECLARE(ks_status_t) ks_pool_free_ex(ks_pool_t *pool, void **addrP);
/*
@ -301,7 +275,7 @@ KS_DECLARE(ks_status_t) ks_pool_free_ex(ks_pool_t *mp_p, void **addrP);
*
* DESCRIPTION:
*
* Ref count increment an address in a memoory pool.
* Ref count increment an address in a memory pool.
*
* RETURNS:
*
@ -311,7 +285,7 @@ KS_DECLARE(ks_status_t) ks_pool_free_ex(ks_pool_t *mp_p, void **addrP);
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool.
* pool -> Pointer to the memory pool.
*
* addr -> The addr to ref
*
@ -319,7 +293,7 @@ KS_DECLARE(ks_status_t) ks_pool_free_ex(ks_pool_t *mp_p, void **addrP);
* a ks_pool error code.
*/
KS_DECLARE(void *) ks_pool_ref_ex(ks_pool_t *mp_p, void *addr, ks_status_t *error_p);
KS_DECLARE(void *) ks_pool_ref_ex(ks_pool_t *pool, void *addr, ks_status_t *error_p);
#define ks_pool_ref(_p, _x) ks_pool_ref_ex(_p, _x, NULL)
@ -328,7 +302,7 @@ KS_DECLARE(void *) ks_pool_ref_ex(ks_pool_t *mp_p, void *addr, ks_status_t *erro
*
* DESCRIPTION:
*
* Reallocate an address in a mmeory pool to a new size.
* Reallocate an address in a memory pool to a new size.
*
* RETURNS:
*
@ -338,22 +312,22 @@ KS_DECLARE(void *) ks_pool_ref_ex(ks_pool_t *mp_p, void *addr, ks_status_t *erro
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool. If NULL then it will do a
* pool -> Pointer to the memory pool. If NULL then it will do a
* normal realloc.
*
* old_addr -> Previously allocated address.
*
* new_byte_size -> New size of the allocation.
* new_size -> New size of the allocation.
*
*/
KS_DECLARE(void *) ks_pool_resize(ks_pool_t *mp_p, void *old_addr, const unsigned long new_byte_size);
KS_DECLARE(void *) ks_pool_resize(ks_pool_t *pool, void *old_addr, const ks_size_t new_size);
/*
* void *ks_pool_resize_ex
*
* DESCRIPTION:
*
* Reallocate an address in a mmeory pool to a new size.
* Reallocate an address in a memory pool to a new size.
*
* RETURNS:
*
@ -363,17 +337,16 @@ KS_DECLARE(void *) ks_pool_resize(ks_pool_t *mp_p, void *old_addr, const unsigne
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool. If NULL then it will do a
* normal realloc.
* pool -> Pointer to the memory pool.
*
* old_addr -> Previously allocated address.
*
* new_byte_size -> New size of the allocation.
* new_size -> New size of the allocation.
*
* error_p <- Pointer to integer which, if not NULL, will be set with
* a ks_pool error code.
*/
KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *mp_p, void *old_addr, const unsigned long new_byte_size, ks_status_t *error_p);
KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *pool, void *old_addr, const ks_size_t new_size, ks_status_t *error_p);
/*
* int ks_pool_stats
@ -390,10 +363,7 @@ KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *mp_p, void *old_addr, const unsi
*
* ARGUMENTS:
*
* mp_p -> Pointer to the memory pool.
*
* page_size_p <- Pointer to an unsigned integer which, if not NULL,
* will be set to the page-size of the pool.
* pool -> Pointer to the memory pool.
*
* num_alloced_p <- Pointer to an unsigned long which, if not NULL,
* will be set to the number of pointers currently allocated in pool.
@ -409,8 +379,7 @@ KS_DECLARE(void *) ks_pool_resize_ex(ks_pool_t *mp_p, void *old_addr, const unsi
* will be set to the total amount of space (including administrative
* overhead) used by the pool.
*/
KS_DECLARE(ks_status_t) ks_pool_stats(const ks_pool_t *mp_p, unsigned int *page_size_p,
unsigned long *num_alloced_p, unsigned long *user_alloced_p, unsigned long *max_alloced_p, unsigned long *tot_alloced_p);
KS_DECLARE(ks_status_t) ks_pool_stats(const ks_pool_t *pool, ks_size_t *num_alloced_p, ks_size_t *user_alloced_p, ks_size_t *max_alloced_p, ks_size_t *tot_alloced_p);
/*
* int ks_pool_set_log_func
@ -428,39 +397,12 @@ KS_DECLARE(ks_status_t) ks_pool_stats(const ks_pool_t *mp_p, unsigned int *page_
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool.
* pool -> Pointer to the memory pool.
*
* log_func -> Log function (defined in ks_pool.h) which will be called
* with each ks_pool transaction.
*/
KS_DECLARE(ks_status_t) ks_pool_set_log_func(ks_pool_t *mp_p, ks_pool_log_func_t log_func);
/*
* int ks_pool_set_max_pages
*
* DESCRIPTION:
*
* Set the maximum number of pages that the library will use. Once it
* hits the limit it will return KS_STATUS_NO_PAGES.
*
* NOTE: if the KS_POOL_FLAG_HEAVY_PACKING is set then this max-pages
* value will include the page with the ks_pool header structure in it.
* If the flag is _not_ set then the max-pages will not include this
* first page.
*
* RETURNS:
*
* Success - KS_STATUS_SUCCESS
*
* Failure - ks_status_t error code
*
* ARGUMENTS:
*
* mp_p <-> Pointer to the memory pool.
*
* max_pages -> Maximum number of pages used by the library.
*/
KS_DECLARE(ks_status_t) ks_pool_set_max_pages(ks_pool_t *mp_p, const unsigned int max_pages);
KS_DECLARE(ks_status_t) ks_pool_set_log_func(ks_pool_t *pool, ks_pool_log_func_t log_func);
/*
* const char *ks_pool_strerror
@ -481,16 +423,16 @@ KS_DECLARE(ks_status_t) ks_pool_set_max_pages(ks_pool_t *mp_p, const unsigned in
*/
KS_DECLARE(const char *) ks_pool_strerror(const ks_status_t error);
KS_DECLARE(ks_status_t) ks_pool_set_cleanup(ks_pool_t *mp_p, void *ptr, void *arg, int type, ks_pool_cleanup_fn_t fn);
KS_DECLARE(ks_status_t) ks_pool_set_cleanup(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_callback_t callback);
#define ks_pool_free(_p, _x) ks_pool_free_ex(_p, (void **)_x)
/*<<<<<<<<<< This is end of the auto-generated output from fillproto. */
KS_DECLARE(char *) ks_pstrdup(ks_pool_t *pool, const char *str);
KS_DECLARE(char *) ks_pstrndup(ks_pool_t *pool, const char *str, size_t len);
KS_DECLARE(char *) ks_pstrmemdup(ks_pool_t *pool, const char *str, size_t len);
KS_DECLARE(void *) ks_pmemdup(ks_pool_t *pool, const void *buf, size_t len);
KS_DECLARE(char *) ks_pstrndup(ks_pool_t *pool, const char *str, ks_size_t len);
KS_DECLARE(char *) ks_pstrmemdup(ks_pool_t *pool, const char *str, ks_size_t len);
KS_DECLARE(void *) ks_pmemdup(ks_pool_t *pool, const void *buf, ks_size_t len);
KS_DECLARE(char *) ks_pstrcat(ks_pool_t *pool, ...);
KS_DECLARE(char *) ks_psprintf(ks_pool_t *pool, const char *fmt, ...);

View File

@ -219,7 +219,7 @@ typedef struct {
char host[48];
} ks_sockaddr_t;
typedef void (*ks_pool_cleanup_fn_t) (ks_pool_t *mpool, void *ptr, void *arg, int type, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t ctype);
typedef void (*ks_pool_cleanup_callback_t)(ks_pool_t *pool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type);
typedef void (*ks_logger_t) (const char *file, const char *func, int line, int level, const char *fmt, ...);
typedef void (*ks_listen_callback_t) (ks_socket_t server_sock, ks_socket_t client_sock, ks_sockaddr_t *addr, void *user_data);

View File

@ -56,9 +56,9 @@ KS_DECLARE(void) ks_random_string(char *buf, uint16_t len, char *set)
}
KS_DECLARE(ks_status_t) ks_global_set_cleanup(ks_pool_cleanup_fn_t fn, void *arg)
KS_DECLARE(ks_status_t) ks_global_set_cleanup(ks_pool_cleanup_callback_t callback, void *arg)
{
return ks_pool_set_cleanup(ks_global_pool(), NULL, arg, 0, fn);
return ks_pool_set_cleanup(ks_global_pool(), NULL, arg, callback);
}
KS_DECLARE(ks_status_t) ks_init(void)

View File

@ -140,7 +140,7 @@ const float max_load_factor = 0.65f;
/*****************************************************************************/
static void ks_hash_cleanup(ks_pool_t *mpool, void *ptr, void *arg, int type, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t ctype)
static void ks_hash_cleanup(ks_pool_t *mpool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
//ks_hash_t *hash = (ks_hash_t *) ptr;
@ -270,7 +270,7 @@ ks_hash_create_ex(ks_hash_t **hp, unsigned int minsize,
*hp = h;
ks_pool_set_cleanup(pool, h, NULL, 0, ks_hash_cleanup);
ks_pool_set_cleanup(pool, h, NULL, ks_hash_cleanup);
return KS_STATUS_SUCCESS;
}

View File

@ -42,7 +42,7 @@ struct ks_mutex {
uint8_t malloc;
};
static void ks_mutex_cleanup(ks_pool_t *mpool, void *ptr, void *arg, int type, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t ctype)
static void ks_mutex_cleanup(ks_pool_t *mpool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
ks_mutex_t *mutex = (ks_mutex_t *) ptr;
@ -150,7 +150,7 @@ KS_DECLARE(ks_status_t) ks_mutex_create(ks_mutex_t **mutex, unsigned int flags,
status = KS_STATUS_SUCCESS;
if (pool) {
ks_pool_set_cleanup(pool, check, NULL, 0, ks_mutex_cleanup);
ks_pool_set_cleanup(pool, check, NULL, ks_mutex_cleanup);
}
done:
@ -224,7 +224,7 @@ struct ks_cond {
uint8_t static_mutex;
};
static void ks_cond_cleanup(ks_pool_t *mpool, void *ptr, void *arg, int type, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t ctype)
static void ks_cond_cleanup(ks_pool_t *mpool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
ks_cond_t *cond = (ks_cond_t *) ptr;
@ -281,7 +281,7 @@ KS_DECLARE(ks_status_t) ks_cond_create_ex(ks_cond_t **cond, ks_pool_t *pool, ks_
*cond = check;
status = KS_STATUS_SUCCESS;
ks_pool_set_cleanup(pool, check, NULL, 0, ks_cond_cleanup);
ks_pool_set_cleanup(pool, check, NULL, ks_cond_cleanup);
done:
return status;
@ -436,7 +436,7 @@ struct ks_rwl {
uint32_t wlc;
};
static void ks_rwl_cleanup(ks_pool_t *mpool, void *ptr, void *arg, int type, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t ctype)
static void ks_rwl_cleanup(ks_pool_t *mpool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
#ifndef WIN32
ks_rwl_t *rwlock = (ks_rwl_t *) ptr;
@ -494,7 +494,7 @@ KS_DECLARE(ks_status_t) ks_rwl_create(ks_rwl_t **rwlock, ks_pool_t *pool)
*rwlock = check;
status = KS_STATUS_SUCCESS;
ks_pool_set_cleanup(pool, check, NULL, 0, ks_rwl_cleanup);
ks_pool_set_cleanup(pool, check, NULL, ks_rwl_cleanup);
done:
return status;
}

File diff suppressed because it is too large Load Diff

View File

@ -56,12 +56,12 @@ struct ks_q_s {
uint8_t active;
};
static void ks_q_cleanup(ks_pool_t *mpool, void *ptr, void *arg, int type, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t ctype)
static void ks_q_cleanup(ks_pool_t *mpool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
ks_q_t *q = (ks_q_t *) ptr;
ks_qnode_t *np, *fp;
if (ctype == KS_MPCL_GLOBAL_FREE) {
if (type == KS_MPCL_GLOBAL_FREE) {
return;
}
@ -202,7 +202,7 @@ KS_DECLARE(ks_status_t) ks_q_create(ks_q_t **qP, ks_pool_t *pool, ks_size_t maxl
q->maxlen = maxlen;
q->active = 1;
ks_pool_set_cleanup(pool, q, NULL, 0, ks_q_cleanup);
ks_pool_set_cleanup(pool, q, NULL, ks_q_cleanup);
*qP = q;

View File

@ -79,7 +79,7 @@ void ks_thread_override_default_stacksize(size_t size)
thread_default_stacksize = size;
}
static void ks_thread_cleanup(ks_pool_t *mpool, void *ptr, void *arg, int type, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t ctype)
static void ks_thread_cleanup(ks_pool_t *mpool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
ks_thread_t *thread = (ks_thread_t *) ptr;
@ -309,7 +309,7 @@ KS_DECLARE(ks_status_t) ks_thread_create_ex(ks_thread_t **rthread, ks_thread_fun
}
*rthread = thread;
ks_pool_set_cleanup(pool, thread, NULL, 0, ks_thread_cleanup);
ks_pool_set_cleanup(pool, thread, NULL, ks_thread_cleanup);
}
return status;

View File

@ -22,7 +22,7 @@ int test1(void)
ks_hash_iterator_t *itt;
ks_hash_write_lock(hash);
for (itt = ks_hash_first(hash, KS_UNLOCKED); itt; itt = ks_hash_next(&itt)) {
for (itt = ks_hash_first(hash, KS_UNLOCKED); itt; ) {
const void *key;
void *val;
@ -31,6 +31,7 @@ int test1(void)
printf("%s=%s\n", (char *)key, (char *)val);
sum2 += atoi(val);
itt = ks_hash_next(&itt);
ks_hash_remove(hash, (char *)key);
}
ks_hash_write_unlock(hash);
@ -95,13 +96,15 @@ int test2(void)
ks_sleep(x * 1000000);
ks_hash_write_lock(hash);
for (itt = ks_hash_first(hash, KS_UNLOCKED); itt; itt = ks_hash_next(&itt)) {
for (itt = ks_hash_first(hash, KS_UNLOCKED); itt; ) {
const void *key;
void *val;
ks_hash_this(itt, &key, NULL, &val);
printf("DEL %s=%s\n", (char *)key, (char *)val);
itt = ks_hash_next(&itt);
ks_hash_remove(hash, (char *)key);
}
ks_hash_write_unlock(hash);

View File

@ -18,7 +18,7 @@ struct foo {
};
void cleanup(ks_pool_t *mpool, void *ptr, void *arg, int type, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t ctype)
void cleanup(ks_pool_t *mpool, void *ptr, void *arg, ks_pool_cleanup_action_t action, ks_pool_cleanup_type_t type)
{
struct foo *foo = (struct foo *) ptr;
@ -158,7 +158,7 @@ int main(int argc, char **argv)
foo->x = 12;
foo->str = strdup("This is a test 1234 abcd; This will be called on explicit free\n");
ks_pool_set_cleanup(pool, foo, NULL, 0, cleanup);
ks_pool_set_cleanup(pool, foo, NULL, cleanup);
printf("FREE OBJ:\n");
@ -184,7 +184,7 @@ int main(int argc, char **argv)
foo->x = 12;
foo->str = strdup("This is a second test 1234 abcd; This will be called on pool clear/destroy\n");
ks_pool_set_cleanup(pool, foo, NULL, 0, cleanup);
ks_pool_set_cleanup(pool, foo, NULL, cleanup);
printf("ALLOC OBJ3: %p\n", (void *)pool);
@ -202,7 +202,7 @@ int main(int argc, char **argv)
printf("CLEANUP: %p\n", (void *)pool);
foo->x = 12;
foo->str = strdup("This is a third test 1234 abcd; This will be called on pool clear/destroy\n");
ks_pool_set_cleanup(pool, foo, NULL, 0, cleanup);
ks_pool_set_cleanup(pool, foo, NULL, cleanup);