최종본

This commit is contained in:
2025-05-10 19:44:45 +09:00
parent be6417cd40
commit 8b486008fa
2 changed files with 14 additions and 8 deletions

View File

@@ -270,7 +270,7 @@ public:
threadPool->enqueueJob(callback, data);
}
};
static void iocpWatcher(ThreadPool* threadPool, int epollfd, std::function<void(ThreadPool*, IOCPPASSINDATA*)> callback) {
static void iocpWatcher(ThreadPool* threadPool, int epollfd, int epollDetroyerFd, std::function<void(ThreadPool*, IOCPPASSINDATA*)> callback) {
struct epoll_event events[FD_SETSIZE];
pthread_t tid = pthread_self();
@@ -280,6 +280,9 @@ public:
struct epoll_event current_event = events[i];
if (current_event.events & EPOLLIN) {
if (current_event.data.fd == epollDetroyerFd) {
return;
}
std::function<void(ThreadPool*, IOCPPASSINDATA*)> task(callback);
threadPool->enqueueJob(socketReader, current_event, epollfd, task);
}
@@ -290,7 +293,7 @@ public:
if (--nready <= 0)
break;
}
threadPool->enqueueJob(iocpWatcher, epollfd, callback);
threadPool->enqueueJob(iocpWatcher, epollfd, epollDetroyerFd, callback);
};
#endif
@@ -307,7 +310,10 @@ public:
#elif __linux__
epollfd_ = ::epoll_create(1);
epollDetroyerFd = ::eventfd(0, EFD_NONBLOCK);
::epoll_ctl(epollfd_, EPOLL_CTL_ADD, epollDetroyerFd, NULL);
struct epoll_event ev;
ev.events = EPOLLIN;
ev.data.fd = epollDetroyerFd;
::epoll_ctl(epollfd_, EPOLL_CTL_ADD, epollDetroyerFd, &ev);
#endif
auto boundFunc = [callback = std::move(callback)](ThreadPool* __IOCPThread, IOCPPASSINDATA* data) mutable {
callback(__IOCPThread, data);
@@ -327,7 +333,7 @@ public:
#elif __linux__
__IOCPThread->respawnWorker(__IOCPThread->threadCount + 1);
spdlog::info("Spawning 1 Epoll Waiter...");
__IOCPThread->enqueueJob(iocpWatcher, epollfd_, boundFunc);
__IOCPThread->enqueueJob(iocpWatcher, epollfd_, epollDetroyerFd, boundFunc);
#endif
}