diff options
author | javabird25 <shockck84@gmail.com> | 2022-03-10 14:48:15 +0500 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-03-10 18:09:27 -0800 |
commit | 1770534d947246a3822b68d302a483be60a56ea1 (patch) | |
tree | 389dcf1bde39364d4414880e12a990ecce453a5b /Userland/Libraries/LibCore/EventLoop.cpp | |
parent | 4660b99ab72f7546d62f1c486a2feb5ade0489f0 (diff) | |
download | serenity-1770534d947246a3822b68d302a483be60a56ea1.zip |
LibCore: Verify that EventLoop is initialized in its static API
Diffstat (limited to 'Userland/Libraries/LibCore/EventLoop.cpp')
-rw-r--r-- | Userland/Libraries/LibCore/EventLoop.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/EventLoop.cpp b/Userland/Libraries/LibCore/EventLoop.cpp index 43200a1ef3..eb1b745294 100644 --- a/Userland/Libraries/LibCore/EventLoop.cpp +++ b/Userland/Libraries/LibCore/EventLoop.cpp @@ -374,8 +374,17 @@ bool connect_to_inspector_server() #endif } +#define VERIFY_EVENT_LOOP_INITIALIZED() \ + do { \ + if (!s_event_loop_stack) { \ + warnln("EventLoop static API was called without prior EventLoop init!"); \ + VERIFY_NOT_REACHED(); \ + } \ + } while (0) + EventLoop& EventLoop::current() { + VERIFY_EVENT_LOOP_INITIALIZED(); return s_event_loop_stack->last(); } @@ -628,6 +637,7 @@ void EventLoop::unregister_signal(int handler_id) void EventLoop::notify_forked(ForkEvent event) { + VERIFY_EVENT_LOOP_INITIALIZED(); switch (event) { case ForkEvent::Child: s_main_event_loop.with_locked([]([[maybe_unused]] auto*& main_event_loop) { main_event_loop = nullptr; }); @@ -815,6 +825,7 @@ Optional<Time> EventLoop::get_next_timer_expiration() int EventLoop::register_timer(Object& object, int milliseconds, bool should_reload, TimerShouldFireWhenNotVisible fire_when_not_visible) { + VERIFY_EVENT_LOOP_INITIALIZED(); VERIFY(milliseconds >= 0); auto timer = make<EventLoopTimer>(); timer->owner = object; @@ -830,6 +841,7 @@ int EventLoop::register_timer(Object& object, int milliseconds, bool should_relo bool EventLoop::unregister_timer(int timer_id) { + VERIFY_EVENT_LOOP_INITIALIZED(); s_id_allocator.with_locked([&](auto& allocator) { allocator->deallocate(timer_id); }); auto it = s_timers->find(timer_id); if (it == s_timers->end()) @@ -840,11 +852,13 @@ bool EventLoop::unregister_timer(int timer_id) void EventLoop::register_notifier(Badge<Notifier>, Notifier& notifier) { + VERIFY_EVENT_LOOP_INITIALIZED(); s_notifiers->set(¬ifier); } void EventLoop::unregister_notifier(Badge<Notifier>, Notifier& notifier) { + VERIFY_EVENT_LOOP_INITIALIZED(); s_notifiers->remove(¬ifier); } |