Implement memory profiler, optimize memory usage, modify code indent (#35)
This commit is contained in:
@ -55,8 +55,8 @@ void * thread_modulers_timer_check(void * arg)
|
||||
while (1) {
|
||||
ms_to_expiry = -1;
|
||||
vm_mutex_lock(&g_timer_ctx_list_mutex);
|
||||
timer_ctx_node_t* elem = (timer_ctx_node_t*) bh_list_first_elem(
|
||||
&g_timer_ctx_list);
|
||||
timer_ctx_node_t* elem = (timer_ctx_node_t*)
|
||||
bh_list_first_elem(&g_timer_ctx_list);
|
||||
while (elem) {
|
||||
int next = check_app_timers(elem->timer_ctx);
|
||||
if (next != -1) {
|
||||
@ -72,7 +72,7 @@ void * thread_modulers_timer_check(void * arg)
|
||||
ms_to_expiry = 60 * 1000;
|
||||
vm_mutex_lock(&g_timer_ctx_list_mutex);
|
||||
vm_cond_reltimedwait(&g_timer_ctx_list_cond, &g_timer_ctx_list_mutex,
|
||||
ms_to_expiry);
|
||||
ms_to_expiry);
|
||||
vm_mutex_unlock(&g_timer_ctx_list_mutex);
|
||||
}
|
||||
}
|
||||
@ -94,20 +94,21 @@ void init_wasm_timer()
|
||||
vm_recursive_mutex_init(&g_timer_ctx_list_mutex);
|
||||
|
||||
vm_thread_create(&tm_tid, thread_modulers_timer_check,
|
||||
NULL,
|
||||
BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
NULL, BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
}
|
||||
|
||||
timer_ctx_t create_wasm_timer_ctx(unsigned int module_id, int prealloc_num)
|
||||
{
|
||||
timer_ctx_t ctx = create_timer_ctx(wasm_timer_callback,
|
||||
wakeup_modules_timer_thread, prealloc_num, module_id);
|
||||
wakeup_modules_timer_thread,
|
||||
prealloc_num,
|
||||
module_id);
|
||||
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
|
||||
timer_ctx_node_t * node = (timer_ctx_node_t*) bh_malloc(
|
||||
sizeof(timer_ctx_node_t));
|
||||
timer_ctx_node_t * node = (timer_ctx_node_t*)
|
||||
bh_malloc(sizeof(timer_ctx_node_t));
|
||||
if (node == NULL) {
|
||||
destroy_timer_ctx(ctx);
|
||||
return NULL;
|
||||
@ -125,8 +126,8 @@ timer_ctx_t create_wasm_timer_ctx(unsigned int module_id, int prealloc_num)
|
||||
void destory_module_timer_ctx(unsigned int module_id)
|
||||
{
|
||||
vm_mutex_lock(&g_timer_ctx_list_mutex);
|
||||
timer_ctx_node_t* elem = (timer_ctx_node_t*) bh_list_first_elem(
|
||||
&g_timer_ctx_list);
|
||||
timer_ctx_node_t* elem = (timer_ctx_node_t*)
|
||||
bh_list_first_elem(&g_timer_ctx_list);
|
||||
while (elem) {
|
||||
if (timer_ctx_get_owner(elem->timer_ctx) == module_id) {
|
||||
bh_list_remove(&g_timer_ctx_list, elem);
|
||||
@ -151,7 +152,7 @@ timer_ctx_t get_wasm_timer_ctx()
|
||||
timer_id_t wasm_create_timer(int interval, bool is_period, bool auto_start)
|
||||
{
|
||||
return sys_create_timer(get_wasm_timer_ctx(), interval, is_period,
|
||||
auto_start);
|
||||
auto_start);
|
||||
}
|
||||
|
||||
void wasm_timer_destory(timer_id_t timer_id)
|
||||
|
||||
@ -40,13 +40,13 @@ void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
|
||||
wasm_data *wasm_app_data = (wasm_data*) m_data->internal_data;
|
||||
wasm_module_inst_t inst = wasm_app_data->wasm_module_inst;
|
||||
|
||||
sensor_event_data_t *payload = (sensor_event_data_t*) bh_message_payload(
|
||||
msg);
|
||||
sensor_event_data_t *payload = (sensor_event_data_t*)
|
||||
bh_message_payload(msg);
|
||||
if (payload == NULL)
|
||||
return;
|
||||
|
||||
func_onSensorEvent = wasm_runtime_lookup_function(inst, "_on_sensor_event",
|
||||
"(i32i32i32)");
|
||||
"(i32i32i32)");
|
||||
if (!func_onSensorEvent) {
|
||||
printf("Cannot find function onRequest\n");
|
||||
} else {
|
||||
@ -54,18 +54,17 @@ void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
|
||||
uint32 sensor_data_len;
|
||||
|
||||
if (payload->data_fmt == FMT_ATTR_CONTAINER) {
|
||||
sensor_data_len = attr_container_get_serialize_length(
|
||||
payload->data);
|
||||
sensor_data_len = attr_container_get_serialize_length(payload->data);
|
||||
} else {
|
||||
printf("Unsupported sensor data format: %d\n", payload->data_fmt);
|
||||
return;
|
||||
}
|
||||
|
||||
sensor_data_offset = wasm_runtime_module_dup_data(inst, payload->data,
|
||||
sensor_data_len);
|
||||
sensor_data_len);
|
||||
if (sensor_data_offset == 0) {
|
||||
printf("Got exception running wasm code: %s\n",
|
||||
wasm_runtime_get_exception(inst));
|
||||
wasm_runtime_get_exception(inst));
|
||||
wasm_runtime_clear_exception(inst);
|
||||
return;
|
||||
}
|
||||
@ -76,7 +75,7 @@ void app_mgr_sensor_event_callback(module_data *m_data, bh_message_t msg)
|
||||
|
||||
if (!wasm_runtime_call_wasm(inst, NULL, func_onSensorEvent, 3, argv)) {
|
||||
printf(":Got exception running wasm code: %s\n",
|
||||
wasm_runtime_get_exception(inst));
|
||||
wasm_runtime_get_exception(inst));
|
||||
wasm_runtime_clear_exception(inst);
|
||||
wasm_runtime_module_free(inst, sensor_data_offset);
|
||||
return;
|
||||
@ -130,17 +129,16 @@ void init_sensor_framework()
|
||||
|
||||
// add the sys sensor objects
|
||||
add_sys_sensor("sensor_test", "This is a sensor for test", 0, 1000,
|
||||
read_test_sensor, config_test_sensor);
|
||||
read_test_sensor, config_test_sensor);
|
||||
|
||||
set_sensor_reshceduler(cb_wakeup_thread);
|
||||
|
||||
wasm_register_msg_callback(SENSOR_EVENT_WASM,
|
||||
app_mgr_sensor_event_callback);
|
||||
app_mgr_sensor_event_callback);
|
||||
|
||||
wasm_register_cleanup_callback(sensor_cleanup_callback);
|
||||
|
||||
vm_thread_create(&tid, (void *)thread_sensor_check, NULL,
|
||||
BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
|
||||
BH_APPLET_PRESERVED_STACK_SIZE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user