MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / plug_holes

Function plug_holes

src/mem.c:119–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

117#endif /* RT_USING_MEMTRACE */
118
119static void plug_holes(struct rt_small_mem *m, struct rt_small_mem_item *mem)
120{
121 struct rt_small_mem_item *nmem;
122 struct rt_small_mem_item *pmem;
123
124 RT_ASSERT((rt_uint8_t *)mem >= m->heap_ptr);
125 RT_ASSERT((rt_uint8_t *)mem < (rt_uint8_t *)m->heap_end);
126
127 /* plug hole forward */
128 nmem = (struct rt_small_mem_item *)&m->heap_ptr[mem->next];
129 if (mem != nmem && !MEM_ISUSED(nmem) &&
130 (rt_uint8_t *)nmem != (rt_uint8_t *)m->heap_end)
131 {
132 /* if mem->next is unused and not end of m->heap_ptr,
133 * combine mem and mem->next
134 */
135 if (m->lfree == nmem)
136 {
137 m->lfree = mem;
138 }
139 nmem->pool_ptr = 0;
140 mem->next = nmem->next;
141 ((struct rt_small_mem_item *)&m->heap_ptr[nmem->next])->prev = (rt_uint8_t *)mem - m->heap_ptr;
142 }
143
144 /* plug hole backward */
145 pmem = (struct rt_small_mem_item *)&m->heap_ptr[mem->prev];
146 if (pmem != mem && !MEM_ISUSED(pmem))
147 {
148 /* if mem->prev is unused, combine mem and mem->prev */
149 if (m->lfree == mem)
150 {
151 m->lfree = pmem;
152 }
153 mem->pool_ptr = 0;
154 pmem->next = mem->next;
155 ((struct rt_small_mem_item *)&m->heap_ptr[mem->next])->prev = (rt_uint8_t *)pmem - m->heap_ptr;
156 }
157}
158
159/**
160 * @brief This function will initialize small memory management algorithm.

Callers 2

rt_smem_reallocFunction · 0.70
rt_smem_freeFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected