Re-org memory allocation interfaces, add --stack-size and --heap-size option (#193)
This commit is contained in:
@ -67,7 +67,21 @@ bh_strdup(const char *s)
|
||||
|
||||
if (s) {
|
||||
size = (uint32)(strlen(s) + 1);
|
||||
if ((s1 = bh_malloc(size)))
|
||||
if ((s1 = BH_MALLOC(size)))
|
||||
bh_memcpy_s(s1, size, s, size);
|
||||
}
|
||||
return s1;
|
||||
}
|
||||
|
||||
char *
|
||||
wa_strdup(const char *s)
|
||||
{
|
||||
uint32 size;
|
||||
char *s1 = NULL;
|
||||
|
||||
if (s) {
|
||||
size = (uint32)(strlen(s) + 1);
|
||||
if ((s1 = WA_MALLOC(size)))
|
||||
bh_memcpy_s(s1, size, s, size);
|
||||
}
|
||||
return s1;
|
||||
|
||||
@ -6,7 +6,6 @@
|
||||
#include "bh_hashmap.h"
|
||||
#include "bh_log.h"
|
||||
#include "bh_thread.h"
|
||||
#include "bh_memory.h"
|
||||
|
||||
|
||||
typedef struct HashMapElem {
|
||||
@ -55,7 +54,7 @@ bh_hash_map_create(uint32 size, bool use_lock,
|
||||
(use_lock ? sizeof(korp_mutex) : 0);
|
||||
|
||||
if (total_size >= UINT32_MAX
|
||||
|| !(map = bh_malloc((uint32)total_size))) {
|
||||
|| !(map = BH_MALLOC((uint32)total_size))) {
|
||||
LOG_ERROR("HashMap create failed: alloc memory failed.\n");
|
||||
return NULL;
|
||||
}
|
||||
@ -68,7 +67,7 @@ bh_hash_map_create(uint32 size, bool use_lock,
|
||||
+ sizeof(HashMapElem) * size);
|
||||
if (vm_mutex_init(map->lock)) {
|
||||
LOG_ERROR("HashMap create failed: init map lock failed.\n");
|
||||
bh_free(map);
|
||||
BH_FREE(map);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -106,7 +105,7 @@ bh_hash_map_insert(HashMap *map, void *key, void *value)
|
||||
elem = elem->next;
|
||||
}
|
||||
|
||||
if (!(elem = bh_malloc(sizeof(HashMapElem)))) {
|
||||
if (!(elem = BH_MALLOC(sizeof(HashMapElem)))) {
|
||||
LOG_ERROR("HashMap insert elem failed: alloc memory failed.\n");
|
||||
goto fail;
|
||||
}
|
||||
@ -233,7 +232,7 @@ bh_hash_map_remove(HashMap *map, void *key,
|
||||
else
|
||||
prev->next = elem->next;
|
||||
|
||||
bh_free(elem);
|
||||
BH_FREE(elem);
|
||||
|
||||
if (map->lock) {
|
||||
vm_mutex_unlock(map->lock);
|
||||
@ -277,7 +276,7 @@ bh_hash_map_destroy(HashMap *map)
|
||||
if (map->value_destroy_func) {
|
||||
map->value_destroy_func(elem->value);
|
||||
}
|
||||
bh_free(elem);
|
||||
BH_FREE(elem);
|
||||
|
||||
elem = next;
|
||||
}
|
||||
@ -287,6 +286,6 @@ bh_hash_map_destroy(HashMap *map)
|
||||
vm_mutex_unlock(map->lock);
|
||||
vm_mutex_destroy(map->lock);
|
||||
}
|
||||
bh_free(map);
|
||||
BH_FREE(map);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
|
||||
#include "bh_queue.h"
|
||||
#include "bh_thread.h"
|
||||
#include "bh_memory.h"
|
||||
#include "bh_time.h"
|
||||
#include "bh_common.h"
|
||||
|
||||
@ -131,7 +130,7 @@ bool bh_post_msg(bh_queue *queue, unsigned short tag, void *body,
|
||||
if (msg == NULL) {
|
||||
queue->drops++;
|
||||
if (len != 0 && body)
|
||||
bh_free(body);
|
||||
BH_FREE(body);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@
|
||||
|
||||
#include "bh_log.h"
|
||||
#include "bh_vector.h"
|
||||
#include "bh_memory.h"
|
||||
|
||||
|
||||
static uint8*
|
||||
@ -18,7 +17,7 @@ alloc_vector_data(uint32 length, uint32 size_elem)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((data = bh_malloc((uint32)total_size))) {
|
||||
if ((data = BH_MALLOC((uint32)total_size))) {
|
||||
memset(data, 0, (uint32)total_size);
|
||||
}
|
||||
|
||||
@ -41,7 +40,7 @@ extend_vector(Vector *vector, uint32 length)
|
||||
}
|
||||
|
||||
memcpy(data, vector->data, vector->size_elem * vector->max_elements);
|
||||
bh_free(vector->data);
|
||||
BH_FREE(vector->data);
|
||||
vector->data = data;
|
||||
vector->max_elements = length;
|
||||
return true;
|
||||
@ -200,7 +199,7 @@ bh_vector_destroy(Vector *vector)
|
||||
}
|
||||
|
||||
if (vector->data)
|
||||
bh_free(vector->data);
|
||||
BH_FREE(vector->data);
|
||||
memset(vector, 0, sizeof(Vector));
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -172,7 +172,7 @@ static void release_timer(timer_ctx_t ctx, app_timer_t * t)
|
||||
vm_mutex_unlock(&ctx->mutex);
|
||||
} else {
|
||||
PRINT("destroy timer :%d\n", t->id);
|
||||
bh_free(t);
|
||||
BH_FREE(t);
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ void release_timer_list(app_timer_t ** p_list)
|
||||
while (t) {
|
||||
app_timer_t *next = t->next;
|
||||
PRINT("destroy timer list:%d\n", t->id);
|
||||
bh_free(t);
|
||||
BH_FREE(t);
|
||||
t = next;
|
||||
}
|
||||
|
||||
@ -199,7 +199,7 @@ timer_ctx_t create_timer_ctx(timer_callback_f timer_handler,
|
||||
check_timer_expiry_f expiery_checker, int prealloc_num,
|
||||
unsigned int owner)
|
||||
{
|
||||
timer_ctx_t ctx = (timer_ctx_t) bh_malloc(sizeof(struct _timer_ctx));
|
||||
timer_ctx_t ctx = (timer_ctx_t) BH_MALLOC(sizeof(struct _timer_ctx));
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
memset(ctx, 0, sizeof(struct _timer_ctx));
|
||||
@ -210,7 +210,7 @@ timer_ctx_t create_timer_ctx(timer_callback_f timer_handler,
|
||||
ctx->owner = owner;
|
||||
|
||||
while (prealloc_num > 0) {
|
||||
app_timer_t *timer = (app_timer_t*) bh_malloc(sizeof(app_timer_t));
|
||||
app_timer_t *timer = (app_timer_t*) BH_MALLOC(sizeof(app_timer_t));
|
||||
if (timer == NULL)
|
||||
goto cleanup;
|
||||
|
||||
@ -231,7 +231,7 @@ timer_ctx_t create_timer_ctx(timer_callback_f timer_handler,
|
||||
|
||||
if (ctx) {
|
||||
release_timer_list(&ctx->free_timers);
|
||||
bh_free(ctx);
|
||||
BH_FREE(ctx);
|
||||
}
|
||||
PRINT("timer ctx create failed\n");
|
||||
return NULL;
|
||||
@ -242,14 +242,14 @@ void destroy_timer_ctx(timer_ctx_t ctx)
|
||||
while (ctx->free_timers) {
|
||||
void * tmp = ctx->free_timers;
|
||||
ctx->free_timers = ctx->free_timers->next;
|
||||
bh_free(tmp);
|
||||
BH_FREE(tmp);
|
||||
}
|
||||
|
||||
cleanup_app_timers(ctx);
|
||||
|
||||
vm_cond_destroy(&ctx->cond);
|
||||
vm_mutex_destroy(&ctx->mutex);
|
||||
bh_free(ctx);
|
||||
BH_FREE(ctx);
|
||||
}
|
||||
|
||||
unsigned int timer_ctx_get_owner(timer_ctx_t ctx)
|
||||
@ -279,7 +279,7 @@ uint32 sys_create_timer(timer_ctx_t ctx, int interval, bool is_period,
|
||||
ctx->free_timers = timer->next;
|
||||
}
|
||||
} else {
|
||||
timer = (app_timer_t*) bh_malloc(sizeof(app_timer_t));
|
||||
timer = (app_timer_t*) BH_MALLOC(sizeof(app_timer_t));
|
||||
if (timer == NULL)
|
||||
return (uint32)-1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user