Lines Matching refs:heap
164 rt_err_t rt_memheap_detach(struct rt_memheap *heap) in rt_memheap_detach() argument
166 RT_ASSERT(heap); in rt_memheap_detach()
167 RT_ASSERT(rt_object_get_type(&heap->parent) == RT_Object_Class_MemHeap); in rt_memheap_detach()
168 RT_ASSERT(rt_object_is_systemobject(&heap->parent)); in rt_memheap_detach()
170 rt_sem_detach(&heap->lock); in rt_memheap_detach()
171 rt_object_detach(&(heap->parent)); in rt_memheap_detach()
187 void *rt_memheap_alloc(struct rt_memheap *heap, rt_size_t size) in rt_memheap_alloc() argument
193 RT_ASSERT(heap != RT_NULL); in rt_memheap_alloc()
194 RT_ASSERT(rt_object_get_type(&heap->parent) == RT_Object_Class_MemHeap); in rt_memheap_alloc()
202 size, RT_NAME_MAX, heap->parent.name); in rt_memheap_alloc()
204 if (size < heap->available_size) in rt_memheap_alloc()
210 if (heap->locked == RT_FALSE) in rt_memheap_alloc()
212 result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); in rt_memheap_alloc()
222 header_ptr = heap->free_list->next_free; in rt_memheap_alloc()
223 while (header_ptr != heap->free_list && free_size < size) in rt_memheap_alloc()
258 new_ptr->pool_ptr = heap; in rt_memheap_alloc()
277 new_ptr->next_free = heap->free_list->next_free; in rt_memheap_alloc()
278 new_ptr->prev_free = heap->free_list; in rt_memheap_alloc()
279 heap->free_list->next_free->prev_free = new_ptr; in rt_memheap_alloc()
280 heap->free_list->next_free = new_ptr; in rt_memheap_alloc()
286 heap->available_size = heap->available_size - in rt_memheap_alloc()
289 if (heap->pool_size - heap->available_size > heap->max_used_size) in rt_memheap_alloc()
290 heap->max_used_size = heap->pool_size - heap->available_size; in rt_memheap_alloc()
295 heap->available_size = heap->available_size - free_size; in rt_memheap_alloc()
296 if (heap->pool_size - heap->available_size > heap->max_used_size) in rt_memheap_alloc()
297 heap->max_used_size = heap->pool_size - heap->available_size; in rt_memheap_alloc()
321 if (heap->locked == RT_FALSE) in rt_memheap_alloc()
324 rt_sem_release(&(heap->lock)); in rt_memheap_alloc()
336 if (heap->locked == RT_FALSE) in rt_memheap_alloc()
339 rt_sem_release(&(heap->lock)); in rt_memheap_alloc()
362 void *rt_memheap_realloc(struct rt_memheap *heap, void *ptr, rt_size_t newsize) in rt_memheap_realloc() argument
369 RT_ASSERT(heap); in rt_memheap_realloc()
370 RT_ASSERT(rt_object_get_type(&heap->parent) == RT_Object_Class_MemHeap); in rt_memheap_realloc()
385 return rt_memheap_alloc(heap, newsize); in rt_memheap_realloc()
398 if (heap->locked == RT_FALSE) in rt_memheap_realloc()
401 result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); in rt_memheap_realloc()
434 heap->available_size = heap->available_size - (newsize - oldsize); in rt_memheap_realloc()
435 if (heap->pool_size - heap->available_size > heap->max_used_size) in rt_memheap_realloc()
436 heap->max_used_size = heap->pool_size - heap->available_size; in rt_memheap_realloc()
458 next_ptr->pool_ptr = heap; in rt_memheap_realloc()
470 next_ptr->next_free = heap->free_list->next_free; in rt_memheap_realloc()
471 next_ptr->prev_free = heap->free_list; in rt_memheap_realloc()
472 heap->free_list->next_free->prev_free = (struct rt_memheap_item *)next_ptr; in rt_memheap_realloc()
473 heap->free_list->next_free = (struct rt_memheap_item *)next_ptr; in rt_memheap_realloc()
477 if (heap->locked == RT_FALSE) in rt_memheap_realloc()
480 rt_sem_release(&(heap->lock)); in rt_memheap_realloc()
487 if (heap->locked == RT_FALSE) in rt_memheap_realloc()
490 rt_sem_release(&(heap->lock)); in rt_memheap_realloc()
494 new_ptr = (void *)rt_memheap_alloc(heap, newsize); in rt_memheap_realloc()
508 if (heap->locked == RT_FALSE) in rt_memheap_realloc()
511 result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); in rt_memheap_realloc()
533 new_ptr->pool_ptr = heap; in rt_memheap_realloc()
552 heap->available_size = heap->available_size - MEMITEM_SIZE(free_ptr); in rt_memheap_realloc()
566 new_ptr->next_free = heap->free_list->next_free; in rt_memheap_realloc()
567 new_ptr->prev_free = heap->free_list; in rt_memheap_realloc()
568 heap->free_list->next_free->prev_free = new_ptr; in rt_memheap_realloc()
569 heap->free_list->next_free = new_ptr; in rt_memheap_realloc()
575 heap->available_size = heap->available_size + MEMITEM_SIZE(new_ptr); in rt_memheap_realloc()
577 if (heap->locked == RT_FALSE) in rt_memheap_realloc()
580 rt_sem_release(&(heap->lock)); in rt_memheap_realloc()
597 struct rt_memheap *heap; in rt_memheap_free() local
625 heap = header_ptr->pool_ptr; in rt_memheap_free()
627 RT_ASSERT(heap); in rt_memheap_free()
628 RT_ASSERT(rt_object_get_type(&heap->parent) == RT_Object_Class_MemHeap); in rt_memheap_free()
630 if (heap->locked == RT_FALSE) in rt_memheap_free()
633 result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); in rt_memheap_free()
645 heap->available_size += MEMITEM_SIZE(header_ptr); in rt_memheap_free()
654 heap->available_size += RT_MEMHEAP_SIZE; in rt_memheap_free()
670 heap->available_size += RT_MEMHEAP_SIZE; in rt_memheap_free()
688 struct rt_memheap_item *n = heap->free_list->next_free; in rt_memheap_free()
691 for (;n != heap->free_list; n = n->next_free) in rt_memheap_free()
714 if (heap->locked == RT_FALSE) in rt_memheap_free()
717 rt_sem_release(&(heap->lock)); in rt_memheap_free()
735 void rt_memheap_info(struct rt_memheap *heap, in rt_memheap_info() argument
742 if (heap->locked == RT_FALSE) in rt_memheap_info()
745 result = rt_sem_take(&(heap->lock), RT_WAITING_FOREVER); in rt_memheap_info()
754 *total = heap->pool_size; in rt_memheap_info()
757 *used = heap->pool_size - heap->available_size; in rt_memheap_info()
760 *max_used = heap->max_used_size; in rt_memheap_info()
762 if (heap->locked == RT_FALSE) in rt_memheap_info()
765 rt_sem_release(&(heap->lock)); in rt_memheap_info()
773 void *_memheap_alloc(struct rt_memheap *heap, rt_size_t size) in _memheap_alloc() argument
778 ptr = rt_memheap_alloc(heap, size); in _memheap_alloc()
798 if (heap == _heap) in _memheap_alloc()
821 void *_memheap_realloc(struct rt_memheap *heap, void *rmem, rt_size_t newsize) in _memheap_realloc() argument
827 return _memheap_alloc(heap, newsize); in _memheap_realloc()
843 new_ptr = _memheap_alloc(heap, newsize); in _memheap_realloc()
868 struct rt_memheap *heap; in memheapcheck() local
881 heap = (struct rt_memheap *)rt_list_entry(node, struct rt_object, list); in memheapcheck()
883 if (name != RT_NULL && rt_strncmp(name, heap->parent.name, RT_NAME_MAX) != 0) in memheapcheck()
886 for (item = heap->block_list; item->next != heap->block_list; item = item->next) in memheapcheck()
896 if (heap != item->pool_ptr) in memheapcheck()
902 …if (!((rt_uintptr_t)item->next <= (rt_uintptr_t)((rt_uintptr_t)heap->start_addr + heap->pool_size)… in memheapcheck()
903 (rt_uintptr_t)item->prev >= (rt_uintptr_t)heap->start_addr) && in memheapcheck()
922 rt_kprintf("name: %s\n", heap->parent.name); in memheapcheck()