EventLoopImplementation.cpp 768 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/NonnullOwnPtr.h>
  7. #include <LibCore/Event.h>
  8. #include <LibCore/EventLoopImplementation.h>
  9. #include <LibCore/ThreadEventQueue.h>
  10. namespace Core {
  11. EventLoopImplementation::EventLoopImplementation()
  12. : m_thread_event_queue(ThreadEventQueue::current())
  13. {
  14. }
  15. EventLoopImplementation::~EventLoopImplementation() = default;
  16. void EventLoopImplementation::post_event(Object& receiver, NonnullOwnPtr<Event>&& event)
  17. {
  18. m_thread_event_queue.post_event(receiver, move(event));
  19. // Wake up this EventLoopImplementation if this is a cross-thread event posting.
  20. if (&ThreadEventQueue::current() != &m_thread_event_queue)
  21. wake();
  22. }
  23. }