Skip to content

Commit

Permalink
eventloop: add destructor and free event source
Browse files Browse the repository at this point in the history
properly free the wl_event_source upon destruction.
  • Loading branch information
gulafaran committed May 31, 2024
1 parent a71bc92 commit c8fd9f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/managers/eventLoop/EventLoopManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ CEventLoopManager::CEventLoopManager() {
m_sTimers.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
}

CEventLoopManager::~CEventLoopManager() {
if (m_sWayland.eventSource)
wl_event_source_remove(m_sWayland.eventSource);
}

static int timerWrite(int fd, uint32_t mask, void* data) {
g_pEventLoopManager->onTimerFire();
return 1;
Expand All @@ -22,7 +27,7 @@ void CEventLoopManager::enterLoop(wl_display* display, wl_event_loop* wlEventLoo
m_sWayland.loop = wlEventLoop;
m_sWayland.display = display;

wl_event_loop_add_fd(wlEventLoop, m_sTimers.timerfd, WL_EVENT_READABLE, timerWrite, nullptr);
m_sWayland.eventSource = wl_event_loop_add_fd(wlEventLoop, m_sTimers.timerfd, WL_EVENT_READABLE, timerWrite, nullptr);

wl_display_run(display);

Expand Down
6 changes: 4 additions & 2 deletions src/managers/eventLoop/EventLoopManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class CEventLoopManager {
public:
CEventLoopManager();
~CEventLoopManager();

void enterLoop(wl_display* display, wl_event_loop* wlEventLoop);

Expand All @@ -24,8 +25,9 @@ class CEventLoopManager {

private:
struct {
wl_event_loop* loop = nullptr;
wl_display* display = nullptr;
wl_event_loop* loop = nullptr;
wl_display* display = nullptr;
wl_event_source* eventSource = nullptr;
} m_sWayland;

struct {
Expand Down

0 comments on commit c8fd9f0

Please sign in to comment.