0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 00:10:59 +01:00

ircd::ctx::ole: Minor interface reorg.

This commit is contained in:
Jason Volk 2019-07-13 14:53:52 -07:00
parent 1af930d541
commit 6e97a72c50
2 changed files with 17 additions and 14 deletions

View file

@ -20,11 +20,7 @@
namespace ircd::ctx::ole
{
struct init;
struct opts;
struct control;
using closure = std::function<void ()>;
void offload(const opts &, const closure &);
struct offload;
}
namespace ircd::ctx
@ -32,7 +28,15 @@ namespace ircd::ctx
using ole::offload;
}
struct ircd::ctx::ole::opts
struct ircd::ctx::offload
{
struct opts;
using closure = std::function<void ()>;
offload(const opts &, const closure &);
};
struct ircd::ctx::ole::offload::opts
{
/// Optionally give this offload task a name for any tasklist.
string_view name;

View file

@ -18,11 +18,11 @@ namespace ircd::ctx::ole
std::mutex mutex;
std::condition_variable cond;
bool termination;
std::deque<closure> queue;
std::deque<offload::closure> queue;
std::vector<std::thread> threads;
closure pop();
void push(closure &&);
offload::closure pop();
void push(offload::closure &&);
void worker() noexcept;
}
@ -51,8 +51,7 @@ noexcept
});
}
void
ircd::ctx::ole::offload(const opts &opts,
ircd::ctx::ole::offload::offload(const opts &opts,
const closure &func)
{
assert(opts.concurrency == 1); // not yet implemented
@ -105,7 +104,7 @@ ircd::ctx::ole::offload(const opts &opts,
std::rethrow_exception(eptr);
}
void
ircd::ctx::ole::push(closure &&func)
ircd::ctx::ole::push(offload::closure &&func)
{
if(unlikely(threads.size() < size_t(thread_max)))
threads.emplace_back(&worker);
@ -141,7 +140,7 @@ catch(const interrupted &)
cond.notify_all();
}
ircd::ctx::ole::closure
ircd::ctx::ole::offload::closure
ircd::ctx::ole::pop()
{
std::unique_lock lock(mutex);