From ad27ad476df210b45ff27ebace5cf11f1c8fcffb Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Thu, 5 Nov 2015 17:11:09 +0300 Subject: [PATCH] AIOContextPool: type aliases for clarity, commentary corrections [#METR-18618] --- dbms/include/DB/Common/AIO.h | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/dbms/include/DB/Common/AIO.h b/dbms/include/DB/Common/AIO.h index 65d3b73e263..ecca6461220 100644 --- a/dbms/include/DB/Common/AIO.h +++ b/dbms/include/DB/Common/AIO.h @@ -66,15 +66,18 @@ class AIOContextPool : public Singleton friend class Singleton; static const auto max_concurrent_events = 128; - static const auto max_timeout_sec = 1; - static const auto max_timeout_nsec = 0; + static const auto timeout_sec = 1; AIOContext aio_context{max_concurrent_events}; - std::size_t id{}; + using id_t = size_t; + using bytes_read_t = ssize_t; + + /// Autoincremental id used to identify completed requests + id_t id{}; mutable std::mutex mutex; mutable std::condition_variable have_resources; - std::map> promises; + std::map> promises; std::atomic cancelled{false}; std::thread io_completion_monitor{&AIOContextPool::monitorForCompletion, this}; @@ -110,11 +113,11 @@ class AIOContextPool : public Singleton int getCompletionEvents(io_event events[], const int max_events) { - timespec timeout{max_timeout_sec, max_timeout_nsec}; + timespec timeout{timeout_sec}; auto num_events = 0; - /// request 1 to `max_concurrent_events` events + /// request 1 to `max_events` events while ((num_events = io_getevents(aio_context.ctx, 1, max_events, events, &timeout)) < 0) if (errno != EINTR) throwFromErrno("io_getevents: Failed to wait for asynchronous IO completion", @@ -160,7 +163,8 @@ class AIOContextPool : public Singleton } public: - std::future post(struct iocb & iocb) + /// Request AIO read operation for iocb, returns a future with number of bytes read + std::future post(struct iocb & iocb) { std::unique_lock lock{mutex}; @@ -168,7 +172,7 @@ public: const auto request_id = id++; /// create a promise and put request in "queue" - promises.emplace(request_id, std::promise{}); + promises.emplace(request_id, std::promise{}); /// store id in AIO request for further identification iocb.aio_data = request_id;