From db3ef016f0b4eb117066df00d67f6abb4d8fea3b Mon Sep 17 00:00:00 2001 From: JackyWoo Date: Wed, 11 Oct 2023 11:20:30 +0800 Subject: [PATCH] Fix data race --- src/Common/NIO/PollSet.cpp | 4 ++-- src/Common/NIO/SocketReactor.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Common/NIO/PollSet.cpp b/src/Common/NIO/PollSet.cpp index 1b53dbd0d7..b21a35aac7 100644 --- a/src/Common/NIO/PollSet.cpp +++ b/src/Common/NIO/PollSet.cpp @@ -211,12 +211,12 @@ class PollSetImpl { struct epoll_event ev; ev.events = 0; - if (mode & PollSet::POLL_READ) - ev.events |= EPOLLIN; if (mode & PollSet::POLL_WRITE) ev.events |= EPOLLOUT; if (mode & PollSet::POLL_ERROR) ev.events |= EPOLLERR; + if (mode & PollSet::POLL_READ) + ev.events |= EPOLLIN; ev.data.ptr = ptr; return epoll_ctl(_epollfd, EPOLL_CTL_ADD, fd, &ev); } diff --git a/src/Common/NIO/SocketReactor.cpp b/src/Common/NIO/SocketReactor.cpp index be54cf3f29..4ae291e37c 100644 --- a/src/Common/NIO/SocketReactor.cpp +++ b/src/Common/NIO/SocketReactor.cpp @@ -169,16 +169,16 @@ void SocketReactor::addEventHandlers(const Socket& socket, const std::vectorhasObserver(*observer)) pNotifier->addObserver(this, *observer); - int mode = 0; if (pNotifier->accepts(_pReadableNotification)) mode |= PollSet::POLL_READ; if (pNotifier->accepts(_pWritableNotification)) mode |= PollSet::POLL_WRITE; if (pNotifier->accepts(_pErrorNotification)) mode |= PollSet::POLL_ERROR; - if (mode) _pollSet.add(socket, mode); } + if (mode) _pollSet.add(socket, mode); }