Started working on a C wrapper

This commit is contained in:
Victor Olin 2023-03-29 08:31:34 +02:00
parent 43ce0ecd71
commit 4f0f8ffef8
3 changed files with 122 additions and 0 deletions

22
src/GC/include/cheap.h Normal file
View file

@ -0,0 +1,22 @@
#ifndef __CHEAP_H__
#define __CHEAP_H__
#ifdef __cplusplus
extern "C" {
#endif
struct cheap;
typedef struct cheap cheap_t;
cheap_t *cheap_the();
void cheap_init();
void cheap_dispose();
void *cheap_alloc(unsigned long size);
void cheap_set_profiler(bool mode);
#ifdef __cplusplus
}
#endif
#endif /* __CHEAP_H__ */

25
src/GC/lib/cheap.cpp Normal file
View file

@ -0,0 +1,25 @@
#pragma once
#include <stdlib.h>
#include "heap.hpp"
#include "cheap.h"
struct cheap {
void *obj;
};
cheap_t *cheap_the() {
cheap_t *c;
GC::Heap *heap;
c = (cheap_t *)malloc(sizeof(*c));
heap = &GC::Heap::the();
c->obj = heap;
return c;
}
void cheap_init() {
GC::Heap::init();
}

75
src/GC/lib/event.cpp Normal file
View file

@ -0,0 +1,75 @@
// #include <chrono>
// #include <iostream>
// #include <list>
#include "chunk.hpp"
#include "event.hpp"
namespace GC
{
/**
* @returns The type of the event
*/
GCEventType GCEvent::get_type()
{
return m_type;
}
/**
* @returns The time the event happened in
* the form of time_t.
*/
std::time_t GCEvent::get_time_stamp()
{
return m_timestamp;
}
/**
* If the event is related to a chunk, this
* function returns the chunk that it is
* related to. If the event is independent
* of a chunk, it returns the nullptr.
*
* @returns A chunk pointer or the nullptr.
*/
const Chunk *GCEvent::get_chunk()
{
return m_chunk;
}
/**
* If the event is an AllocStart event, this
* returns the size of the alloc() request.
* otherwise this returns 0.
*
* @returns A number representing the number
* of bytes requested to alloc()
* or 0 if the event is not an
* AllocStart event.
*/
size_t GCEvent::get_size()
{
return m_size;
}
/**
* @returns The string conversion of the event type.
*/
const char *GCEvent::type_to_string()
{
switch (m_type)
{
case HeapInit: return "HeapInit";
case AllocStart: return "AllocStart";
case CollectStart: return "CollectStart";
case MarkStart: return "MarkStart";
case ChunkMarked: return "ChunkMarked";
case ChunkSwept: return "ChunkSwept";
case ChunkFreed: return "ChunkFreed";
case NewChunk: return "NewChunk";
case ReusedChunk: return "ReusedChunk";
case ProfilerDispose: return "ProfilerDispose";
default: return "[Unknown]";
}
}
}