Re-org memory allocation interfaces, add --stack-size and --heap-size option (#193)
This commit is contained in:
@ -27,7 +27,6 @@
|
||||
#include "bh_common.h"
|
||||
#include "bh_queue.h"
|
||||
#include "bh_thread.h"
|
||||
#include "bh_memory.h"
|
||||
#include "runtime_sensor.h"
|
||||
#include "bi-inc/attr_container.h"
|
||||
#include "module_wasm_app.h"
|
||||
@ -462,54 +461,50 @@ static bool parse_args(int argc, char *argv[])
|
||||
// Driver function
|
||||
int iwasm_main(int argc, char *argv[])
|
||||
{
|
||||
RuntimeInitArgs init_args;
|
||||
korp_thread tid;
|
||||
|
||||
if (!parse_args(argc, argv))
|
||||
return -1;
|
||||
|
||||
#if 1
|
||||
if (bh_memory_init_with_pool(global_heap_buf, sizeof(global_heap_buf))
|
||||
memset(&init_args, 0, sizeof(RuntimeInitArgs));
|
||||
|
||||
#if USE_GLOBAL_HEAP_BUF != 0
|
||||
init_args.mem_alloc_type = Alloc_With_Pool;
|
||||
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
|
||||
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
|
||||
#else
|
||||
if (bh_memory_init_with_allocator(malloc, free)
|
||||
init_args.mem_alloc_type = Alloc_With_Allocator;
|
||||
init_args.mem_alloc_option.allocator.malloc_func = malloc;
|
||||
init_args.mem_alloc_option.allocator.realloc_func = realloc;
|
||||
init_args.mem_alloc_option.allocator.free_func = free;
|
||||
#endif
|
||||
!= 0) {
|
||||
printf("Init global heap failed.\n");
|
||||
|
||||
/* initialize runtime environment */
|
||||
if (!wasm_runtime_full_init(&init_args)) {
|
||||
bh_printf("Init runtime environment failed.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vm_thread_sys_init() != 0) {
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
//
|
||||
// timer manager
|
||||
//
|
||||
/* timer manager */
|
||||
init_wasm_timer();
|
||||
|
||||
|
||||
//
|
||||
// connection framework
|
||||
//
|
||||
/* connection framework */
|
||||
if (!init_connection_framework()) {
|
||||
vm_thread_sys_destroy();
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
//
|
||||
// sensor framework
|
||||
//
|
||||
/* sensor framework */
|
||||
init_sensor_framework();
|
||||
// add the sys sensor objects
|
||||
add_sys_sensor("sensor_test",
|
||||
"This is a sensor for test",
|
||||
0,
|
||||
1000,
|
||||
read_test_sensor,
|
||||
"This is a sensor for test",
|
||||
0,
|
||||
1000,
|
||||
read_test_sensor,
|
||||
config_test_sensor);
|
||||
start_sensor_framework();
|
||||
|
||||
|
||||
|
||||
#ifndef CONNECTION_UART
|
||||
if (server_mode)
|
||||
vm_thread_create(&tid, func_server_mode, NULL,
|
||||
@ -527,7 +522,7 @@ int iwasm_main(int argc, char *argv[])
|
||||
exit_connection_framework();
|
||||
|
||||
fail1:
|
||||
bh_memory_destroy();
|
||||
wasm_runtime_destroy();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user