changes to hooks

This commit is contained in:
2021-05-10 20:51:41 +02:00
parent d7f060d848
commit 458f35241d
+13 -13
View File
@@ -50,28 +50,28 @@ struct Lambda<R(Args...)>
}; };
struct Hook : Array_List<Lambda<void()>> { struct Hook {
Array_List<Lambda<void()>> lambdas;
Hook() { Hook() {
alloc(); lambdas.alloc();
} }
~Hook () { ~Hook () {
dealloc(); lambdas.dealloc();
} }
void operator<<(Lambda<void()> f) { void operator<<(Lambda<void()> f) {
// FIXME(Felix): Why can I not call Array_List::append here??? Hallo? // FIXME(Felix): Why can I not call Array_List::append here??? Hallo?
if (count == length) { if (lambdas.count == lambdas.length) {
length *= 2; lambdas.length *= 2;
data = (Lambda<void()>*)realloc(data, length * sizeof(Lambda<void()>)); lambdas.data = (Lambda<void()>*)realloc(lambdas.data, lambdas.length * sizeof(Lambda<void()>));
} }
data[count] = f; lambdas.data[lambdas.count] = f;
count++; lambdas.count++;
} }
void operator()() { void operator()() {
while(count --> 0) { while(lambdas.count --> 0) {
fflush(stdout); lambdas.data[lambdas.count]();
data[count]();
} }
count = 0; lambdas.count = 0;
} }
}; };
@@ -79,6 +79,6 @@ struct __System_Shutdown_Hook : Hook {
void operator()() = delete; void operator()() = delete;
~__System_Shutdown_Hook() { ~__System_Shutdown_Hook() {
Hook::operator()(); Hook::operator()();
dealloc(); lambdas.dealloc();
} }
} system_shutdown_hook; } system_shutdown_hook;