[mem] Modify macro definitions for better code reading
This commit is contained in:
parent
1a8b8522f7
commit
acf4487177
22
src/mem.c
22
src/mem.c
|
@ -87,16 +87,12 @@ struct rt_small_mem
|
|||
|
||||
#define HEAP_MAGIC 0x1ea0
|
||||
|
||||
#ifdef ARCH_CPU_64BIT
|
||||
#define MIN_SIZE 24
|
||||
#else
|
||||
#define MIN_SIZE 12
|
||||
#endif /* ARCH_CPU_64BIT */
|
||||
#define MIN_SIZE (sizeof(rt_ubase_t) + sizeof(rt_size_t) + sizeof(rt_size_t))
|
||||
|
||||
#define MEM_MASK ((~(rt_size_t)0) - 1)
|
||||
|
||||
#define MEM_USED() ((((rt_base_t)(small_mem)) & MEM_MASK) | 0x1)
|
||||
#define MEM_FREED() ((((rt_base_t)(small_mem)) & MEM_MASK) | 0x0)
|
||||
#define MEM_USED(_mem) ((((rt_base_t)(_mem)) & MEM_MASK) | 0x1)
|
||||
#define MEM_FREED(_mem) ((((rt_base_t)(_mem)) & MEM_MASK) | 0x0)
|
||||
#define MEM_ISUSED(_mem) \
|
||||
(((rt_base_t)(((struct rt_small_mem_item *)(_mem))->pool_ptr)) & (~MEM_MASK))
|
||||
#define MEM_POOL(_mem) \
|
||||
|
@ -220,7 +216,7 @@ rt_smem_t rt_smem_init(const char *name,
|
|||
|
||||
/* initialize the start of the heap */
|
||||
mem = (struct rt_small_mem_item *)small_mem->heap_ptr;
|
||||
mem->pool_ptr = MEM_FREED();
|
||||
mem->pool_ptr = MEM_FREED(small_mem);
|
||||
mem->next = small_mem->mem_size_aligned + SIZEOF_STRUCT_MEM;
|
||||
mem->prev = 0;
|
||||
#ifdef RT_USING_MEMTRACE
|
||||
|
@ -229,7 +225,7 @@ rt_smem_t rt_smem_init(const char *name,
|
|||
|
||||
/* initialize the end of the heap */
|
||||
small_mem->heap_end = (struct rt_small_mem_item *)&small_mem->heap_ptr[mem->next];
|
||||
small_mem->heap_end->pool_ptr = MEM_USED();
|
||||
small_mem->heap_end->pool_ptr = MEM_USED(small_mem);
|
||||
small_mem->heap_end->next = small_mem->mem_size_aligned + SIZEOF_STRUCT_MEM;
|
||||
small_mem->heap_end->prev = small_mem->mem_size_aligned + SIZEOF_STRUCT_MEM;
|
||||
#ifdef RT_USING_MEMTRACE
|
||||
|
@ -333,7 +329,7 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size)
|
|||
|
||||
/* create mem2 struct */
|
||||
mem2 = (struct rt_small_mem_item *)&small_mem->heap_ptr[ptr2];
|
||||
mem2->pool_ptr = MEM_FREED();
|
||||
mem2->pool_ptr = MEM_FREED(small_mem);
|
||||
mem2->next = mem->next;
|
||||
mem2->prev = ptr;
|
||||
#ifdef RT_USING_MEMTRACE
|
||||
|
@ -365,7 +361,7 @@ void *rt_smem_alloc(rt_smem_t m, rt_size_t size)
|
|||
small_mem->parent.max = small_mem->parent.used;
|
||||
}
|
||||
/* set small memory object */
|
||||
mem->pool_ptr = MEM_USED();
|
||||
mem->pool_ptr = MEM_USED(small_mem);
|
||||
#ifdef RT_USING_MEMTRACE
|
||||
if (rt_thread_self())
|
||||
rt_smem_setname(mem, rt_thread_self()->parent.name);
|
||||
|
@ -462,7 +458,7 @@ void *rt_smem_realloc(rt_smem_t m, void *rmem, rt_size_t newsize)
|
|||
|
||||
ptr2 = ptr + SIZEOF_STRUCT_MEM + newsize;
|
||||
mem2 = (struct rt_small_mem_item *)&small_mem->heap_ptr[ptr2];
|
||||
mem2->pool_ptr = MEM_FREED();
|
||||
mem2->pool_ptr = MEM_FREED(small_mem);
|
||||
mem2->next = mem->next;
|
||||
mem2->prev = ptr;
|
||||
#ifdef RT_USING_MEMTRACE
|
||||
|
@ -530,7 +526,7 @@ void rt_smem_free(void *rmem)
|
|||
(rt_ubase_t)(mem->next - ((rt_uint8_t *)mem - small_mem->heap_ptr)));
|
||||
|
||||
/* ... and is now unused. */
|
||||
mem->pool_ptr = MEM_FREED();
|
||||
mem->pool_ptr = MEM_FREED(small_mem);
|
||||
#ifdef RT_USING_MEMTRACE
|
||||
rt_smem_setname(mem, " ");
|
||||
#endif /* RT_USING_MEMTRACE */
|
||||
|
|
Loading…
Reference in New Issue