Implemented IsTraceFinished, removed global linked list
This commit is contained in:
parent
c6ff6ad31d
commit
d3722aac83
2 changed files with 16 additions and 13 deletions
|
@ -16,7 +16,6 @@ int TracingHeap_Create(TracingHeap* self, allocator_t* allocator)
|
|||
|
||||
self->allocator = allocator;
|
||||
|
||||
self->objects = NULL;
|
||||
self->black_objects = NULL;
|
||||
self->white_objects = NULL;
|
||||
self->grey_objects = NULL;
|
||||
|
@ -40,7 +39,13 @@ void TracingHeap_Destroy(TracingHeap* self)
|
|||
return;
|
||||
}
|
||||
|
||||
for (TracingObject* object = self->objects; object != NULL; object = object->global_next) {
|
||||
for (TracingObject* object = self->white_objects; object != NULL; object = object->color_next) {
|
||||
_TracingHeap_ForceDestroyObject(self, object);
|
||||
}
|
||||
for (TracingObject* object = self->grey_objects; object != NULL; object = object->color_next) {
|
||||
_TracingHeap_ForceDestroyObject(self, object);
|
||||
}
|
||||
for (TracingObject* object = self->black_objects; object != NULL; object = object->color_next) {
|
||||
_TracingHeap_ForceDestroyObject(self, object);
|
||||
}
|
||||
|
||||
|
@ -199,6 +204,11 @@ int TracingHeap_BeginTrace(TracingHeap* self)
|
|||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
bool TracingHeap_IsTraceFinished(TracingHeap* self)
|
||||
{
|
||||
return self->grey_objects == NULL;
|
||||
}
|
||||
|
||||
int TracingHeap_EndTrace(TracingHeap* self)
|
||||
{
|
||||
if (self == NULL) {
|
||||
|
@ -212,11 +222,11 @@ int TracingHeap_EndTrace(TracingHeap* self)
|
|||
TracingObject* unreachable_object = *unreachable_list;
|
||||
|
||||
while (unreachable_object != NULL) {
|
||||
TracingObject* next_unreachable = unreachable_object->global_next;
|
||||
TracingObject* next_unreachable = unreachable_object->color_next;
|
||||
|
||||
if (_TracingHeap_DestroyObject(self, unreachable_object)) {
|
||||
*unreachable_list = unreachable_object;
|
||||
unreachable_object->global_prev = NULL;
|
||||
unreachable_object->color_prev = NULL;
|
||||
return ECANCELED;
|
||||
}
|
||||
|
||||
|
@ -246,11 +256,5 @@ void* TracingHeap_Allocate(TracingHeap* self, size_t bytes)
|
|||
*reachable_list_start = object;
|
||||
object->color_prev = NULL;
|
||||
|
||||
|
||||
object->global_next = self->objects; // link before global object list
|
||||
object->global_prev = NULL; // no previous object
|
||||
self->objects->global_prev = object; // link first object via previous link
|
||||
self->objects = object; // insert into linked list
|
||||
|
||||
return object->data;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "../allocator-interface/allocator-interface.h"
|
||||
|
||||
#include <stdalign.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
enum TracingColor {
|
||||
TRACINGCOLOR_BLACK,
|
||||
|
@ -12,8 +13,6 @@ enum TracingColor {
|
|||
};
|
||||
|
||||
typedef struct TracingObject {
|
||||
struct TracingObject* global_next;
|
||||
struct TracingObject* global_prev;
|
||||
struct TracingObject* color_next;
|
||||
struct TracingObject* color_prev;
|
||||
enum TracingColor color;
|
||||
|
@ -39,7 +38,6 @@ typedef struct TracingHeapConfig_s {
|
|||
} TracingHeapConfig;
|
||||
|
||||
typedef struct TracingHeap_s {
|
||||
TracingObject* objects;
|
||||
TracingObject* white_objects;
|
||||
TracingObject* grey_objects;
|
||||
TracingObject* black_objects;
|
||||
|
@ -57,6 +55,7 @@ void TracingHeap_Destroy(TracingHeap* self);
|
|||
void* TracingHeap_Allocate(TracingHeap* self, size_t bytes);
|
||||
|
||||
int TracingHeap_BeginTrace(TracingHeap* self);
|
||||
bool TracingHeap_IsTraceFinished(TracingHeap* self);
|
||||
int TracingHeap_EndTrace(TracingHeap* self);
|
||||
int TracingHeap_TraceNext(TracingHeap* self);
|
||||
size_t TracingHeap_TraceNextN(TracingHeap* self, size_t n);
|
||||
|
|
Loading…
Reference in a new issue