libutil: add async io roots to threadpool threads

this needs a new method because overloading rules would make a pair of
methods taking `std::function`s of different argument types ambiguous.
we could've turned enqueue into a template and made `enqueueWithAio` a
private method too, but the necessary template magic is wasted on this

Change-Id: I93ccfde07126c287ad2a4dc5a07caec6a9d83944
This commit is contained in:
eldritch horrors
2025-02-04 13:10:21 +00:00
parent 4138fc7622
commit 3ce789acb5
2 changed files with 12 additions and 4 deletions
+4 -2
View File
@@ -41,7 +41,7 @@ void ThreadPool::shutdown()
thr.join();
}
void ThreadPool::enqueue(const work_t & t)
void ThreadPool::enqueueWithAio(const work_t & t)
{
auto state(state_.lock());
if (quit)
@@ -95,6 +95,8 @@ void ThreadPool::doWork()
bool didWork = false;
std::exception_ptr exc;
AsyncIoRoot aio;
while (true) {
work_t w;
{
@@ -157,7 +159,7 @@ void ThreadPool::doWork()
}
try {
w();
w(aio);
} catch (...) {
exc = std::current_exception();
}
+8 -2
View File
@@ -1,6 +1,7 @@
#pragma once
///@file
#include "lix/libutil/async.hh"
#include "lix/libutil/error.hh"
#include "lix/libutil/sync.hh"
@@ -31,12 +32,17 @@ public:
*
* \todo use std::packaged_task?
*/
typedef std::function<void()> work_t;
typedef std::function<void(AsyncIoRoot &)> work_t;
/**
* Enqueue a function to be executed by the thread pool.
*/
void enqueue(const work_t & t);
void enqueueWithAio(const work_t & t);
void enqueue(std::function<void()> t)
{
enqueueWithAio([t{std::move(t)}](AsyncIoRoot &) { t(); });
}
/**
* Execute work items until the queue is empty.