提交 89579537 authored 作者: Shane Bryldt's avatar Shane Bryldt

FS-10167: Temporary commit half way through memory lifecycle changes towards isolated memory pools

上级 61330012
...@@ -1052,7 +1052,7 @@ blade_connection_state_hook_t blade_transport_wss_on_state_attach_inbound(blade_ ...@@ -1052,7 +1052,7 @@ blade_connection_state_hook_t blade_transport_wss_on_state_attach_inbound(blade_
} }
if (!bs) { if (!bs) {
blade_session_create(&bs, bh); blade_session_create(&bs, bh, NULL);
ks_assert(bs); ks_assert(bs);
ks_log(KS_LOG_DEBUG, "Session (%s) created\n", blade_session_id_get(bs)); ks_log(KS_LOG_DEBUG, "Session (%s) created\n", blade_session_id_get(bs));
...@@ -1200,11 +1200,9 @@ blade_connection_state_hook_t blade_transport_wss_on_state_attach_outbound(blade ...@@ -1200,11 +1200,9 @@ blade_connection_state_hook_t blade_transport_wss_on_state_attach_outbound(blade
} }
if (!bs) { if (!bs) {
blade_session_create(&bs, bh); // @todo let sid be passed to constructor, NULL to generate blade_session_create(&bs, bh, sid);
ks_assert(bs); ks_assert(bs);
blade_session_id_set(bs, sid);
ks_log(KS_LOG_DEBUG, "Session (%s) created\n", blade_session_id_get(bs)); ks_log(KS_LOG_DEBUG, "Session (%s) created\n", blade_session_id_get(bs));
blade_session_read_lock(bs, KS_TRUE); // this will be done by blade_handle_sessions_get() otherwise blade_session_read_lock(bs, KS_TRUE); // this will be done by blade_handle_sessions_get() otherwise
......
...@@ -300,9 +300,7 @@ KS_DECLARE(ks_status_t) blade_handle_startup(blade_handle_t *bh, config_setting_ ...@@ -300,9 +300,7 @@ KS_DECLARE(ks_status_t) blade_handle_startup(blade_handle_t *bh, config_setting_
} }
} }
// @todo load DSOs // @todo load internal modules, call onload and onstartup
// @todo call onload and onstartup callbacks for modules from DSOs
if (ks_thread_create_ex(&bh->worker_thread, if (ks_thread_create_ex(&bh->worker_thread,
blade_handle_worker_thread, blade_handle_worker_thread,
...@@ -332,6 +330,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh) ...@@ -332,6 +330,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh)
ks_hash_remove(bh->requests, key); ks_hash_remove(bh->requests, key);
blade_request_destroy(&value); blade_request_destroy(&value);
// @todo note to self, fix this when switching to auto cleanup, as hash invalidates iterator when removing
} }
for (it = ks_hash_first(bh->sessions, KS_UNLOCKED); it; it = ks_hash_next(&it)) { for (it = ks_hash_first(bh->sessions, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
...@@ -344,8 +343,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh) ...@@ -344,8 +343,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh)
} }
while (ks_hash_count(bh->sessions) > 0) ks_sleep_ms(100); while (ks_hash_count(bh->sessions) > 0) ks_sleep_ms(100);
// @todo call onshutdown and onunload callbacks for modules from DSOs, which will unregister transports and spaces, and will disconnect remaining // @todo unload internal modules, call onshutdown and onunload
// unattached connections
while ((it = ks_hash_first(bh->events, KS_UNLOCKED))) { while ((it = ks_hash_first(bh->events, KS_UNLOCKED))) {
void *key = NULL; void *key = NULL;
...@@ -353,6 +351,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh) ...@@ -353,6 +351,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh)
ks_hash_this(it, (const void **)&key, NULL, (void **)&value); ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
blade_handle_event_unregister(bh, (const char *)key); blade_handle_event_unregister(bh, (const char *)key);
// @todo note to self, fix this when switching to auto cleanup, as hash invalidates iterator when removing
} }
while ((it = ks_hash_first(bh->spaces, KS_UNLOCKED))) { while ((it = ks_hash_first(bh->spaces, KS_UNLOCKED))) {
...@@ -361,6 +360,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh) ...@@ -361,6 +360,7 @@ KS_DECLARE(ks_status_t) blade_handle_shutdown(blade_handle_t *bh)
ks_hash_this(it, (const void **)&key, NULL, (void **)&value); ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
blade_handle_space_unregister(value); blade_handle_space_unregister(value);
// @todo note to self, fix this when switching to auto cleanup, as hash invalidates iterator when removing
} }
// @todo unload DSOs // @todo unload DSOs
...@@ -888,7 +888,7 @@ void *blade_handle_worker_thread(ks_thread_t *thread, void *data) ...@@ -888,7 +888,7 @@ void *blade_handle_worker_thread(ks_thread_t *thread, void *data)
{ {
blade_handle_t *bh = NULL; blade_handle_t *bh = NULL;
blade_connection_t *bc = NULL; blade_connection_t *bc = NULL;
blade_session_t *bs = NULL; //blade_session_t *bs = NULL;
ks_hash_iterator_t *it = NULL; ks_hash_iterator_t *it = NULL;
ks_q_t *cleanup = NULL; ks_q_t *cleanup = NULL;
...@@ -917,21 +917,21 @@ void *blade_handle_worker_thread(ks_thread_t *thread, void *data) ...@@ -917,21 +917,21 @@ void *blade_handle_worker_thread(ks_thread_t *thread, void *data)
blade_connection_destroy(&bc); blade_connection_destroy(&bc);
} }
ks_hash_write_lock(bh->sessions); //ks_hash_write_lock(bh->sessions);
for (it = ks_hash_first(bh->sessions, KS_UNLOCKED); it; it = ks_hash_next(&it)) { //for (it = ks_hash_first(bh->sessions, KS_UNLOCKED); it; it = ks_hash_next(&it)) {
void *key = NULL; // void *key = NULL;
blade_session_t *value = NULL; // blade_session_t *value = NULL;
ks_hash_this(it, (const void **)&key, NULL, (void **)&value); // ks_hash_this(it, (const void **)&key, NULL, (void **)&value);
if (blade_session_state_get(value) == BLADE_SESSION_STATE_CLEANUP) ks_q_push(cleanup, value); // if (blade_session_state_get(value) == BLADE_SESSION_STATE_CLEANUP) ks_q_push(cleanup, value);
} //}
ks_hash_write_unlock(bh->sessions); //ks_hash_write_unlock(bh->sessions);
while (ks_q_trypop(cleanup, (void **)&bs) == KS_STATUS_SUCCESS) { //while (ks_q_trypop(cleanup, (void **)&bs) == KS_STATUS_SUCCESS) {
blade_handle_sessions_remove(bs); // blade_handle_sessions_remove(bs);
blade_session_destroy(&bs); // blade_session_destroy(&bs);
} //}
ks_sleep_ms(500); ks_sleep_ms(500);
} }
......
...@@ -36,14 +36,12 @@ ...@@ -36,14 +36,12 @@
#include <blade.h> #include <blade.h>
KS_BEGIN_EXTERN_C KS_BEGIN_EXTERN_C
KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle_t *bh); KS_DECLARE(ks_status_t) blade_session_create(blade_session_t **bsP, blade_handle_t *bh, const char *sid);
KS_DECLARE(ks_status_t) blade_session_destroy(blade_session_t **bsP); KS_DECLARE(ks_status_t) blade_session_destroy(blade_session_t **bsP);
KS_DECLARE(ks_status_t) blade_session_startup(blade_session_t *bs); KS_DECLARE(ks_status_t) blade_session_startup(blade_session_t *bs);
KS_DECLARE(ks_status_t) blade_session_shutdown(blade_session_t *bs); KS_DECLARE(ks_status_t) blade_session_shutdown(blade_session_t *bs);
KS_DECLARE(blade_handle_t *) blade_session_handle_get(blade_session_t *bs); KS_DECLARE(blade_handle_t *) blade_session_handle_get(blade_session_t *bs);
KS_DECLARE(ks_pool_t *) blade_session_pool_get(blade_session_t *bs);
KS_DECLARE(const char *) blade_session_id_get(blade_session_t *bs); KS_DECLARE(const char *) blade_session_id_get(blade_session_t *bs);
KS_DECLARE(void) blade_session_id_set(blade_session_t *bs, const char *id);
KS_DECLARE(blade_session_state_t) blade_session_state_get(blade_session_t *bs); KS_DECLARE(blade_session_state_t) blade_session_state_get(blade_session_t *bs);
KS_DECLARE(cJSON *) blade_session_properties_get(blade_session_t *bs); KS_DECLARE(cJSON *) blade_session_properties_get(blade_session_t *bs);
KS_DECLARE(ks_status_t) blade_session_read_lock(blade_session_t *bs, ks_bool_t block); KS_DECLARE(ks_status_t) blade_session_read_lock(blade_session_t *bs, ks_bool_t block);
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
#include <blade.h> #include <blade.h>
#define BLADE_HANDLE_TPOOL_MIN 2 #define BLADE_HANDLE_TPOOL_MIN 2
#define BLADE_HANDLE_TPOOL_MAX 8 #define BLADE_HANDLE_TPOOL_MAX 4096
#define BLADE_HANDLE_TPOOL_STACK (1024 * 256) #define BLADE_HANDLE_TPOOL_STACK (1024 * 256)
#define BLADE_HANDLE_TPOOL_IDLE 10 #define BLADE_HANDLE_TPOOL_IDLE 10
......
...@@ -54,7 +54,7 @@ struct ks_pool_prefix_s { ...@@ -54,7 +54,7 @@ struct ks_pool_prefix_s {
ks_pool_cleanup_callback_t cleanup_callback; ks_pool_cleanup_callback_t cleanup_callback;
void *cleanup_arg; void *cleanup_arg;
ks_size_t magic4; ks_size_t magic4;
ks_size_t reserved[2]; ks_size_t reserved[2]; // @todo use one of these to store the original pool address to validate that free_mem is not attempted against the wrong pool, which can corrupt the allocation linked list
}; };
#define KS_POOL_PREFIX_SIZE sizeof(ks_pool_prefix_t) #define KS_POOL_PREFIX_SIZE sizeof(ks_pool_prefix_t)
...@@ -287,7 +287,7 @@ static void *alloc_mem(ks_pool_t *pool, const ks_size_t size, ks_status_t *error ...@@ -287,7 +287,7 @@ static void *alloc_mem(ks_pool_t *pool, const ks_size_t size, ks_status_t *error
required = KS_POOL_PREFIX_SIZE + size + KS_POOL_FENCE_SIZE; required = KS_POOL_PREFIX_SIZE + size + KS_POOL_FENCE_SIZE;
start = malloc(required); start = malloc(required);
ks_assert(start); ks_assert(start);
memset(start, 0, required); memset(start, 0, required); // @todo consider readding the NO_ZERO flag option, which would reduce this to only zero out PREFIX_SIZE instead of the entire allocation.
prefix = (ks_pool_prefix_t *)start; prefix = (ks_pool_prefix_t *)start;
addr = (void *)((ks_byte_t *)start + KS_POOL_PREFIX_SIZE); addr = (void *)((ks_byte_t *)start + KS_POOL_PREFIX_SIZE);
...@@ -701,6 +701,7 @@ KS_DECLARE(void *) ks_pool_calloc_ex(ks_pool_t *pool, const ks_size_t ele_n, con ...@@ -701,6 +701,7 @@ KS_DECLARE(void *) ks_pool_calloc_ex(ks_pool_t *pool, const ks_size_t ele_n, con
ks_mutex_lock(pool->mutex); ks_mutex_lock(pool->mutex);
addr = alloc_mem(pool, size, &ret); addr = alloc_mem(pool, size, &ret);
// @todo consider readding the NO_ZERO flag option, in which case must zero the user-space here based on expected calloc behaviour... memset(addr, 0, size);
ks_mutex_unlock(pool->mutex); ks_mutex_unlock(pool->mutex);
if (pool->log_func != NULL) { if (pool->log_func != NULL) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论