2024-02-05 22:25:30 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Vector.h"
|
|
|
|
#include "BaseObj.h"
|
|
|
|
#include "ehs/system/Mutex.h"
|
|
|
|
#include "ehs/system/Thread.h"
|
|
|
|
|
|
|
|
namespace ehs
|
|
|
|
{
|
|
|
|
typedef bool (*GcLogic)(BaseObj*);
|
|
|
|
|
2024-07-24 01:36:20 -07:00
|
|
|
class EHS_LIB_IO GC
|
2024-02-05 22:25:30 -08:00
|
|
|
{
|
|
|
|
private:
|
2024-06-29 22:20:53 -07:00
|
|
|
static Array<GcLogic> logic;
|
2024-02-05 22:25:30 -08:00
|
|
|
static Vector<BaseObj*> garbage;
|
|
|
|
static UInt_64 max;
|
|
|
|
static Thread thread;
|
|
|
|
static Mutex mutex;
|
|
|
|
static bool running;
|
|
|
|
|
|
|
|
static bool Has(const BaseObj* obj);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void Start();
|
|
|
|
|
|
|
|
static void Stop();
|
|
|
|
|
2024-06-29 22:20:53 -07:00
|
|
|
static bool HasLogic(GcLogic logicCb);
|
|
|
|
|
|
|
|
static bool AddLogic(GcLogic logicCb);
|
|
|
|
|
2024-02-05 22:25:30 -08:00
|
|
|
/// Adds an object to the garbage pile to be deleted.
|
|
|
|
/// @param[in] obj The object to be deleted.
|
|
|
|
static void Add(BaseObj* obj);
|
|
|
|
|
|
|
|
/// Sets the maximum amount of garbage to delete per poll.
|
|
|
|
/// @param[in] newMax The new maximum.
|
2024-07-01 20:23:17 -07:00
|
|
|
static void SetMax(UInt_64 newMax);
|
2024-02-05 22:25:30 -08:00
|
|
|
|
|
|
|
/// Gets the maximum amount of garbage to delete per poll.
|
|
|
|
/// @returns The maximum.
|
|
|
|
static UInt_64 GetMax();
|
|
|
|
|
|
|
|
/// Sets a new amount for memory pre-allocation to save on memory operations.
|
|
|
|
/// @param[in] newStride The stride to pre-allocate.
|
2024-07-01 20:23:17 -07:00
|
|
|
static void SetStride(UInt_64 newStride);
|
2024-02-05 22:25:30 -08:00
|
|
|
|
|
|
|
/// The amount of data pre-allocated to save on memory operations.
|
|
|
|
/// @returns The stride.
|
|
|
|
static UInt_64 GetStride();
|
|
|
|
|
|
|
|
/// Gets the garbage count.
|
|
|
|
/// @returns Garbage count.
|
|
|
|
static UInt_64 Size();
|
|
|
|
|
|
|
|
/// Used to delete objects over time.
|
|
|
|
static void Poll();
|
|
|
|
|
|
|
|
/// Deletes all of the data at once.
|
|
|
|
/// @warning Use Poll instead to prevent stutter.
|
|
|
|
static void Dump();
|
|
|
|
|
|
|
|
static bool IsRunning();
|
2024-06-29 22:20:53 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool ShouldDelete(BaseObj *obj);
|
2024-02-05 22:25:30 -08:00
|
|
|
};
|
|
|
|
}
|