feat: add data-kind to TracingObject to enable quasi-polymorphism
This commit is contained in:
parent
7120f59951
commit
3d6f7a2957
2 changed files with 49 additions and 16 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include <stdalign.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
enum TracingColor {
|
||||
TRACINGCOLOR_BLACK,
|
||||
|
@ -12,29 +13,43 @@ enum TracingColor {
|
|||
TRACINGCOLOR_WHITE,
|
||||
};
|
||||
|
||||
union TracingObjectDataAlignment {
|
||||
double d;
|
||||
void* p;
|
||||
};
|
||||
|
||||
typedef struct TracingObject {
|
||||
// color linked list members
|
||||
struct TracingObject* color_next;
|
||||
struct TracingObject* color_prev;
|
||||
enum TracingColor color;
|
||||
|
||||
// Selector for the callback function
|
||||
// TODO: Think about something for 16-bit systems
|
||||
#define TRACINGHEAPDATAKIND_MAX (((uint64_t) 1 << 62) - 1)
|
||||
uint64_t data_kind: 62;
|
||||
|
||||
// color of this object
|
||||
enum TracingColor color: 2;
|
||||
|
||||
// data member of the requested size
|
||||
alignas(void*) char data[];
|
||||
alignas(union TracingObjectDataAlignment) char data[];
|
||||
} TracingObject;
|
||||
|
||||
|
||||
typedef int (*TracingHeapVisit) (void* context, void* reference);
|
||||
typedef int (*TracingHeapTraceData) (void* context, void* data, TracingHeapVisit trace_callback, void* callback_context);
|
||||
typedef int (*TracingHeapDataDestructor) (void* context, void* data);
|
||||
typedef size_t (*TracingHeapSizeQuery) (void* context, void* data);
|
||||
|
||||
typedef struct TracingHeapConfig_s {
|
||||
TracingHeapTraceData trace_data;
|
||||
void* trace_context;
|
||||
TracingHeapTraceData* trace_data;
|
||||
void** trace_context;
|
||||
|
||||
TracingHeapDataDestructor destructor;
|
||||
void* destructor_context;
|
||||
TracingHeapDataDestructor* destructor;
|
||||
void** destructor_context;
|
||||
|
||||
TracingHeapSizeQuery size_query;
|
||||
void* size_query_context;
|
||||
TracingHeapSizeQuery* size_query;
|
||||
void** size_query_context;
|
||||
} TracingHeapConfig;
|
||||
|
||||
typedef struct TracingHeap_s {
|
||||
|
@ -52,7 +67,7 @@ typedef struct TracingHeap_s {
|
|||
int TracingHeap_Create(TracingHeap* self, allocator_t* allocator);
|
||||
void TracingHeap_Destroy(TracingHeap* self);
|
||||
|
||||
void* TracingHeap_Allocate(TracingHeap* self, size_t bytes);
|
||||
void* TracingHeap_Allocate(TracingHeap* self, size_t bytes, uint64_t object_kind);
|
||||
|
||||
int TracingHeap_BeginTrace(TracingHeap* self);
|
||||
bool TracingHeap_IsTraceFinished(TracingHeap* self);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue