mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 08:12:37 +01:00
ircd::ctx::ole: Minor interface reorg.
This commit is contained in:
parent
1af930d541
commit
6e97a72c50
2 changed files with 17 additions and 14 deletions
|
@ -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;
|
||||
|
|
|
@ -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,9 +51,8 @@ noexcept
|
|||
});
|
||||
}
|
||||
|
||||
void
|
||||
ircd::ctx::ole::offload(const opts &opts,
|
||||
const closure &func)
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue