일단 iocp는 완성한 듯 윈도우에서만 되면 될 듯

This commit is contained in:
2025-05-02 19:30:37 +09:00
parent 7fabc98456
commit 181d30ff28
10 changed files with 147 additions and 53 deletions

View File

@@ -4,10 +4,12 @@ namespace Chattr {
Thread::Thread(Thread&& other) noexcept {
other.detach();
memcpy(this, &other, sizeof(Thread));
}
Thread& Thread::operator=(Thread&& other) noexcept {
other.detach();
memcpy(this, &other, sizeof(Thread));
return *this;
}
@@ -16,8 +18,6 @@ Thread::~Thread() {
spdlog::critical("There is not joined thread");
std::exit(EXIT_FAILURE);
}
if (returnValuePtr != nullptr)
delete returnValuePtr;
}
void Thread::detach() {

View File

@@ -63,11 +63,16 @@ void* ThreadPool::Worker() {
#elif __linux__
pthread_t pid = pthread_self();
#endif
spdlog::debug("ThreadPool Worker : {} up", pid);
while (!terminate_) {
std::unique_lock<std::mutex> lock(jobQueueMutex);
jobQueueCV_.wait(lock, [this]() { return !this->jobs_.empty() || terminate_; });
if (this->jobs_.empty())
if (this->jobs_.empty() || terminate_) {
jobs_ = std::queue<std::packaged_task<void()>>();
break;
}
if (this->jobs_.empty())
continue;
auto job = std::move(jobs_.front());
jobs_.pop();
@@ -76,6 +81,7 @@ void* ThreadPool::Worker() {
spdlog::debug("ThreadPool Worker : {} Executing a job", pid);
job();
}
spdlog::debug("ThreadPool Worker : {} down", pid);
return nullptr;
}