mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-07 05:06:36 +02:00
Initial version of gc_heap_free()
This commit is contained in:
parent
aa93c2c487
commit
a2dccabdb7
2 changed files with 24 additions and 1 deletions
24
gc.c
24
gc.c
|
@ -212,6 +212,28 @@ gc_heap *gc_heap_create(int heap_type, size_t size, size_t max_size,
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Free a page of the heap
|
||||||
|
* @usage
|
||||||
|
* @param page Page to free
|
||||||
|
* @param prev_page Previous page in the heap
|
||||||
|
* @return Previous page if successful, NULL otherwise
|
||||||
|
*/
|
||||||
|
gc_heap *gc_heap_free(gc_heap *page, gc_heap *prev_page)
|
||||||
|
{
|
||||||
|
// At least for now, do not free first page
|
||||||
|
if (prev_page == NULL || page == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#if GC_DEBUG_PRINTFS
|
||||||
|
fprintf(stderr, "DEBUG freeing heap page at addr: %p\n", page);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
prev_page->next = page->next;
|
||||||
|
free(page);
|
||||||
|
return prev_page;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print heap usage information.
|
* Print heap usage information.
|
||||||
* Before calling this function the current thread must have the heap lock
|
* Before calling this function the current thread must have the heap lock
|
||||||
|
@ -615,7 +637,7 @@ size_t gc_sweep(gc_heap * h, int heap_type, size_t * sum_freed_ptr)
|
||||||
size_t freed, max_freed = 0, heap_freed = 0, sum_freed = 0, size;
|
size_t freed, max_freed = 0, heap_freed = 0, sum_freed = 0, size;
|
||||||
object p, end;
|
object p, end;
|
||||||
gc_free_list *q, *r, *s;
|
gc_free_list *q, *r, *s;
|
||||||
gc_heap *orig_heap_ptr = h;
|
gc_heap *orig_heap_ptr = h, *prev_h = h;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Lock the heap to prevent issues with allocations during sweep
|
// Lock the heap to prevent issues with allocations during sweep
|
||||||
|
|
|
@ -571,6 +571,7 @@ void gc_add_mutator(gc_thread_data * thd);
|
||||||
void gc_remove_mutator(gc_thread_data * thd);
|
void gc_remove_mutator(gc_thread_data * thd);
|
||||||
gc_heap *gc_heap_create(int heap_type, size_t size, size_t max_size,
|
gc_heap *gc_heap_create(int heap_type, size_t size, size_t max_size,
|
||||||
size_t chunk_size);
|
size_t chunk_size);
|
||||||
|
gc_heap *gc_heap_free(gc_heap *page, gc_heap *prev_page);
|
||||||
void gc_print_stats(gc_heap * h);
|
void gc_print_stats(gc_heap * h);
|
||||||
int gc_grow_heap(gc_heap * h, int heap_type, size_t size, size_t chunk_size);
|
int gc_grow_heap(gc_heap * h, int heap_type, size_t size, size_t chunk_size);
|
||||||
char *gc_copy_obj(object hp, char *obj, gc_thread_data * thd);
|
char *gc_copy_obj(object hp, char *obj, gc_thread_data * thd);
|
||||||
|
|
Loading…
Add table
Reference in a new issue