From 186e13930dcd638c345b9bcf890d7de2ebc89ab7 Mon Sep 17 00:00:00 2001 From: botbw Date: Mon, 23 Sep 2024 14:38:09 +0800 Subject: [PATCH] [chore] refine --- csrc/backend.cpp | 6 ++++-- csrc/pthread_backend.cpp | 10 ++++------ include/asyncio.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/csrc/backend.cpp b/csrc/backend.cpp index e00495d..98e40ff 100644 --- a/csrc/backend.cpp +++ b/csrc/backend.cpp @@ -53,12 +53,14 @@ void probe_asyncio(const std::string &backend) #else throw std::runtime_error("backend aio is not installed\n"); #endif - } else { + } else if (backend == "pthread") { #ifndef DISABLE_PTHREAD aio.reset(new PthreadAsyncIO(2)); #else throw std::runtime_error("backend pthread is not installed\n"); #endif + } else { + throw std::runtime_error("unknown backend"); } int fd = fileno(fp); @@ -88,7 +90,7 @@ void probe_asyncio(const std::string &backend) for (int i = 0; i < n_loop; i++) { for (int j = 0; j < n_len; j++) - { + { assert(text[i][j] == new_text[i][j]); } } diff --git a/csrc/pthread_backend.cpp b/csrc/pthread_backend.cpp index 3ddb429..601fc33 100644 --- a/csrc/pthread_backend.cpp +++ b/csrc/pthread_backend.cpp @@ -36,12 +36,10 @@ void PthreadAsyncIO::readv(int fd, const iovec *iov, unsigned int iovcnt, unsign this->read_fut.push_back(std::make_tuple(std::move(fut), callback)); } - void PthreadAsyncIO::get_event(WaitType wt) { if (wt == NOWAIT) return; this->sync_write_events(); this->sync_read_events(); - } void PthreadAsyncIO::sync_write_events() { @@ -49,10 +47,10 @@ void PthreadAsyncIO::sync_write_events() { auto front = std::move(this->write_fut.front()); this->write_fut.pop_front(); - std::future fut(std::move(std::get<0>(front))); + auto fut(std::move(std::get<0>(front))); fut.wait(); - callback_t callback = std::get<1>(front); + auto callback = std::get<1>(front); if (callback != nullptr) { callback(); } @@ -64,10 +62,10 @@ void PthreadAsyncIO::sync_read_events() { auto front = std::move(this->read_fut.front()); this->read_fut.pop_front(); - std::future fut(std::move(std::get<0>(front))); + auto fut(std::move(std::get<0>(front))); fut.wait(); - callback_t callback = std::get<1>(front); + auto callback = std::get<1>(front); if (callback != nullptr) { callback(); } diff --git a/include/asyncio.h b/include/asyncio.h index d7f6886..d479123 100644 --- a/include/asyncio.h +++ b/include/asyncio.h @@ -8,7 +8,7 @@ using callback_t = std::function; enum IOType { WRITE, - READ, + READ }; enum WaitType