From 27d8bc7cad4a8f68c2da3efbb77f45ec70ae40e6 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期三, 05 一月 2022 14:11:39 +0800 Subject: [PATCH] pb.go MsgQueryProcReply add subLocalTopics and subNetTopics --- src/shm/mm.cpp | 91 +++++++++++++++++++++++++++++++++++++++------ 1 files changed, 79 insertions(+), 12 deletions(-) diff --git a/src/shm/mm.cpp b/src/shm/mm.cpp index 13ec443..bcfc1a7 100644 --- a/src/shm/mm.cpp +++ b/src/shm/mm.cpp @@ -3,7 +3,10 @@ */ #include "mm.h" #include "sem_util.h" +#include "hashtable.h" +#include "key_def.h" #include "logger_factory.h" +#include "bh_api.h" #include <sys/sem.h> #include <sys/shm.h> @@ -61,8 +64,6 @@ #define PREV_FBLKP(bp) (*PREDRP(bp)) /* $end mallocmacros */ - - // #define MAX_HEAP (512*(1<<20)) /* 20 MB */ #define MAX_HEAP (512) /* 20 MB */ @@ -135,9 +136,12 @@ /* * mm_free - Free a block */ -void mm_free(void *ptr) +void mm_free(void *ptr, int enable) { - if (ptr == 0) + if (ptr == 0) + return; + + if (check_mm_valid(ptr) == false) return; /* @@ -147,15 +151,19 @@ *} */ - SemUtil::dec_uni(mutex); + if (enable == true) { + SemUtil::dec_uni(mutex); + } + ptr -= SIZE_T_SIZE; size_t size = GET_SIZE(HDRP(ptr)); PUT(HDRP(ptr), PACK(size, 0)); PUT(FTRP(ptr), PACK(size, 0)); + *(size_t *)ptr = 0x00; coalesce(ptr); - SemUtil::inc(mutex); + if (enable == true) { + SemUtil::inc(mutex); + } } - - /* * mm_realloc - Naive implementation of realloc @@ -389,15 +397,13 @@ PUT(HDRP(bp), PACK(size, 0)); /* Free block header */ //line:vm:mm:freeblockhdr PUT(FTRP(bp), PACK(size, 0)); /* Free block footer */ //line:vm:mm:freeblockftr PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1)); /* New epilogue header */ //line:vm:mm:newepihdr - + /* Coalesce if the previous block was free */ return coalesce(bp); //line:vm:mm:returnblock } static void insert_fblock (void *bp) { - //鍚庤繘鍏堝嚭鐨勬柟寮忔彃鍏ワ紝鍗虫彃鍏ラ摼琛ㄥご浣嶇疆 - // insert into the header of the free list PUT_PTR(SUCCRP(bp), NEXT_FBLKP(heap_listp)); //the successor of bp point to the old first free block PUT_PTR(PREDRP(NEXT_FBLKP(heap_listp)), bp); //the predecessor of the old first free block point to bp @@ -489,7 +495,10 @@ PUT(FTRP(bp), PACK(csize, 1)); rm_fblock(bp); } - return bp; + + *(size_t *)bp = inter_key_get(); + + return (bp + SIZE_T_SIZE); } static int is_allocated(void *ptr) @@ -514,20 +523,78 @@ } +void find_mm_data(int val) +{ + void *bp = heap_listp; + + unsigned int diff; + struct timeval start, end; + + gettimeofday(&start, NULL); + SemUtil::dec(mutex); + for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0; bp = NEXT_BLKP(bp)) + { + if (GET_ALLOC(HDRP(bp))) { + if ((*(size_t *)bp) == val) { + mm_free(bp + SIZE_T_SIZE, false); + } + } + + gettimeofday(&end, NULL); + + diff = end.tv_sec - start.tv_sec; + if (diff >= TIME_DUR) + break; + } + SemUtil::inc(mutex); + + return; +} + +int check_mm_valid(void *bp) +{ + int val; + + if ((bp >= mem_start_brk) && (bp <= mem_max_addr) && (GET_ALLOC(HDRP(bp - SIZE_T_SIZE)))) { + + val = *(size_t *)(bp - SIZE_T_SIZE); + if ((val >= START_KEY) || (val == SHM_BUS_KEY)) { + return true; + } + + return false; + } + + return false; +} + /* * find_fit - Find a fit for a block with size bytes */ static void *find_fit(size_t size) { void *bp; + unsigned int diff; + struct timeval start, end; + gettimeofday(&start, NULL); for (bp = NEXT_FBLKP(heap_listp); bp != heap_listp; bp = NEXT_FBLKP(bp)) { if (!GET_ALLOC(HDRP(bp)) && (size <= GET_SIZE(HDRP(bp)))) { return bp; + } else if (GET_ALLOC(HDRP(bp)) && (GET_SIZE(HDRP(bp)) == 0)) + { + break; } + + gettimeofday(&end, NULL); + + diff = end.tv_sec - start.tv_sec; + if (diff >= TIME_DUR) + break; } + return NULL; /* No fit */ } -- Gitblit v1.8.0