From d07058934b6dc651e6b7d69250db5205c5040aae Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Sat, 19 Nov 2022 17:13:02 +0800 Subject: [PATCH] bugfixed: can't use global malloc_allocator --- HISTORY | 3 ++- make.sh | 24 +++++++++++++++++------- src/fast_allocator.c | 8 ++++---- src/fast_allocator.h | 17 +++++++++-------- 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/HISTORY b/HISTORY index ad9dc94..248354b 100644 --- a/HISTORY +++ b/HISTORY @@ -1,7 +1,8 @@ -Version 1.64 2022-11-10 +Version 1.64 2022-11-19 * shared_func.[hc]: normalize_path use type string_t for general purpose * bugfixed: common_blocked_queue_[alloc|free]_node must use lock + * bugfixed: can't use global malloc_allocator Version 1.63 2022-10-16 * sockopt.[hc]: getIpAndPort support ipv6 diff --git a/make.sh b/make.sh index 16b9c90..b5564af 100755 --- a/make.sh +++ b/make.sh @@ -53,19 +53,30 @@ done /bin/rm -f a.out $tmp_src_filename +uname=$(uname) TARGET_PREFIX=$DESTDIR/usr if [ "$int_bytes" -eq 8 ]; then - OS_BITS=64 - LIB_VERSION=lib64 + OS_BITS=64 + if [ $uname = 'Linux' ]; then + osname=$(cat /etc/os-release | grep -w NAME | awk -F '=' '{print $2;}' | \ + awk -F '"' '{if (NF==3) {print $2} else {print $1}}' | awk '{print $1}') + if [ $osname = 'Ubuntu' -o $osname = 'Debian' ]; then + LIB_VERSION=lib + else + LIB_VERSION=lib64 + fi + else + LIB_VERSION=lib + fi else - OS_BITS=32 - LIB_VERSION=lib + OS_BITS=32 + LIB_VERSION=lib fi if [ "$off_bytes" -eq 8 ]; then - OFF_BITS=64 + OFF_BITS=64 else - OFF_BITS=32 + OFF_BITS=32 fi DEBUG_FLAG=0 @@ -101,7 +112,6 @@ elif [ "$uname" = "FreeBSD" ] || [ "$uname" = "Darwin" ]; then if [ "$uname" = "Darwin" ]; then CFLAGS="$CFLAGS -DDARWIN" TARGET_PREFIX=$TARGET_PREFIX/local - LIB_VERSION=lib fi if [ -f /usr/include/sys/vmmeter.h ]; then diff --git a/src/fast_allocator.c b/src/fast_allocator.c index 3d32608..9d3870f 100644 --- a/src/fast_allocator.c +++ b/src/fast_allocator.c @@ -25,8 +25,6 @@ #define BYTES_ALIGN(x, pad_mask) (((x) + pad_mask) & (~pad_mask)) -static struct fast_allocator_info malloc_allocator; - #define ADD_ALLOCATOR_TO_ARRAY(acontext, allocator, _pooled) \ do { \ (allocator)->index = acontext->allocator_array.count; \ @@ -341,7 +339,9 @@ int fast_allocator_init_ex(struct fast_allocator_context *acontext, return result; } - ADD_ALLOCATOR_TO_ARRAY(acontext, &malloc_allocator, false); + ADD_ALLOCATOR_TO_ARRAY(acontext, &acontext-> + allocator_array.malloc_allocator, false); + /* logInfo("sizeof(struct fast_allocator_wrapper): %d, allocator_array count: %d", (int)sizeof(struct fast_allocator_wrapper), acontext->allocator_array.count); @@ -414,7 +414,7 @@ static struct fast_allocator_info *get_allocator(struct fast_allocator_context } } - return &malloc_allocator; + return &acontext->allocator_array.malloc_allocator; } int fast_allocator_retry_reclaim(struct fast_allocator_context *acontext, diff --git a/src/fast_allocator.h b/src/fast_allocator.h index 1271c80..46c3750 100644 --- a/src/fast_allocator.h +++ b/src/fast_allocator.h @@ -46,14 +46,15 @@ struct fast_region_info struct fast_allocator_array { - int count; - int alloc; - int reclaim_interval; //< 0 for never reclaim - int last_reclaim_time; - volatile int64_t malloc_bytes; //total alloc bytes - int64_t malloc_bytes_limit; //water mark bytes for malloc - double expect_usage_ratio; - struct fast_allocator_info **allocators; + int count; + int alloc; + int reclaim_interval; //< 0 for never reclaim + int last_reclaim_time; + volatile int64_t malloc_bytes; //total alloc bytes + int64_t malloc_bytes_limit; //water mark bytes for malloc + double expect_usage_ratio; + struct fast_allocator_info malloc_allocator; + struct fast_allocator_info **allocators; }; struct fast_allocator_wrapper {