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:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user