eventloop: RAII the even source on readable fd
RAII remove the event source and honor rule by 5
This commit is contained in:
parent
ceec1943ff
commit
4a30e2acd9
2 changed files with 17 additions and 5 deletions
|
|
@ -77,11 +77,6 @@ void CEventLoopManager::onFdReadable(SReadableWaiter* waiter) {
|
|||
UP<SReadableWaiter> taken = std::move(*it);
|
||||
m_readableWaiters.erase(it);
|
||||
|
||||
if (taken->source) {
|
||||
wl_event_source_remove(taken->source);
|
||||
taken->source = nullptr;
|
||||
}
|
||||
|
||||
if (taken->fn)
|
||||
taken->fn();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,23 @@ class CEventLoopManager {
|
|||
wl_event_source* source;
|
||||
Hyprutils::OS::CFileDescriptor fd;
|
||||
std::function<void()> fn;
|
||||
|
||||
SReadableWaiter(wl_event_source* src, Hyprutils::OS::CFileDescriptor f, std::function<void()> func) : source(src), fd(std::move(f)), fn(std::move(func)) {}
|
||||
|
||||
~SReadableWaiter() {
|
||||
if (source) {
|
||||
wl_event_source_remove(source);
|
||||
source = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// copy
|
||||
SReadableWaiter(const SReadableWaiter&) = delete;
|
||||
SReadableWaiter& operator=(const SReadableWaiter&) = delete;
|
||||
|
||||
// move
|
||||
SReadableWaiter(SReadableWaiter&& other) noexcept = default;
|
||||
SReadableWaiter& operator=(SReadableWaiter&& other) noexcept = default;
|
||||
};
|
||||
|
||||
// schedule function to when fd is readable (WL_EVENT_READABLE / POLLIN),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue