diff --git a/src/GC/include/event.hpp b/src/GC/include/event.hpp index cee4ded..cf4a57f 100644 --- a/src/GC/include/event.hpp +++ b/src/GC/include/event.hpp @@ -15,7 +15,9 @@ namespace GC { MarkStart, ChunkMarked, ChunkSwept, - ChunkFreed + ChunkFreed, + NewChunk, + ReusedChunk }; using TimeStamp = chrono::_V2::system_clock::time_point; diff --git a/src/GC/include/heap.hpp b/src/GC/include/heap.hpp index fc6cc9c..2338878 100644 --- a/src/GC/include/heap.hpp +++ b/src/GC/include/heap.hpp @@ -64,6 +64,7 @@ namespace GC { size_t m_size; size_t m_allocated_size; uintptr_t *m_stack_top = nullptr; + bool m_profiler_enable = false; // maybe change to std::list std::vector m_allocated_chunks; @@ -92,5 +93,6 @@ namespace GC { void collect(uint flags); // conditional collection void check_init(); // print dummy things void print_contents(); // print dummy things + void set_profiler(bool mode); }; } \ No newline at end of file diff --git a/src/GC/include/profiler.hpp b/src/GC/include/profiler.hpp index 5a3f3b4..2055c18 100644 --- a/src/GC/include/profiler.hpp +++ b/src/GC/include/profiler.hpp @@ -27,7 +27,7 @@ namespace GC { return m_instance; } - inline static Profiler *m_instance; + inline static Profiler *m_instance = nullptr; vector m_events; public: diff --git a/src/GC/lib/event.cpp b/src/GC/lib/event.cpp index 2936a27..e1367db 100644 --- a/src/GC/lib/event.cpp +++ b/src/GC/lib/event.cpp @@ -28,5 +28,6 @@ namespace GC { void GCEvent::printFull() { assert(false && "TODO: unimplemented"); + ostream s1 = cout; } } \ No newline at end of file diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index 31f4b2e..69f25a8 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -404,4 +404,9 @@ namespace GC { cout << "NO FREED CHUNKS" << endl; } } + + void Heap::set_profiler(bool mode) { + auto heap = Heap::the(); + heap->m_profiler_enable = mode; + } } \ No newline at end of file diff --git a/src/GC/tests/events.cpp b/src/GC/tests/events.cpp new file mode 100644 index 0000000..e517092 --- /dev/null +++ b/src/GC/tests/events.cpp @@ -0,0 +1,44 @@ +#include +#include + +using namespace std; +// broken :( +// [event_source(native)] +class ESource { +public: + __event void TestEvent(int eValue); +}; + +// [event_receiver(native)] +class EReceiver { +public: + void Handler1(int eValue) { + cout << "Handler1 with: " << eValue << endl; + } + + void Handler2(int eValue) { + cout << "Handler2 with: " << eValue << endl; + } + + void hookEvent(ESource *eSource) { + __hook(&ESource::TestEvent, eSource, &EReceiver::Handler1); + __hook(&ESource::TestEvent, eSource, &EReceiver::Handler2); + } + + void unhookEvent(ESource *eSource) { + __unhook(&ESource::TestEvent, eSource, &EReceiver::Handler1); + __unhook(&ESource::TestEvent, eSource, &EReceiver::Handler2); + } +}; + +int main() { + + ESource src; + EReceiver rcv; + + rcv.hookEvent(&src); + __raise src.TestEvent(12); + rcv.unhookEvent(&src); + + return 0; +} \ No newline at end of file