2018-02-04 03:22:01 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
2016-09-27 10:40:33 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_CTX_OLE_H
|
|
|
|
|
2017-09-09 16:30:45 +02:00
|
|
|
/// Context OffLoad Engine (OLE).
|
|
|
|
///
|
|
|
|
/// This system allows moving a task off the main IRCd thread by passing a function to a
|
|
|
|
/// worker thread for execution. The context on the main IRCd thread yields until the offload
|
2017-09-16 18:41:10 +02:00
|
|
|
/// function has returned (or thrown).
|
2017-09-09 16:30:45 +02:00
|
|
|
///
|
2017-08-28 23:51:22 +02:00
|
|
|
namespace ircd::ctx::ole
|
|
|
|
{
|
|
|
|
struct init;
|
2019-09-03 20:09:32 +02:00
|
|
|
struct opts;
|
2019-07-13 23:53:52 +02:00
|
|
|
struct offload;
|
2017-08-28 23:51:22 +02:00
|
|
|
}
|
2016-09-27 10:40:33 +02:00
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
namespace ircd::ctx
|
|
|
|
{
|
|
|
|
using ole::offload;
|
|
|
|
}
|
2016-09-27 10:40:33 +02:00
|
|
|
|
2020-02-01 21:31:37 +01:00
|
|
|
struct ircd::ctx::ole::offload
|
2019-07-13 23:53:52 +02:00
|
|
|
{
|
2019-09-03 20:09:32 +02:00
|
|
|
using function = std::function<void ()>;
|
2019-07-13 23:53:52 +02:00
|
|
|
|
2019-09-03 20:09:32 +02:00
|
|
|
offload(const opts &, const function &);
|
|
|
|
offload(const function &);
|
2019-07-13 23:53:52 +02:00
|
|
|
};
|
|
|
|
|
2019-09-03 20:09:32 +02:00
|
|
|
struct ircd::ctx::ole::opts
|
2019-07-11 23:31:48 +02:00
|
|
|
{
|
|
|
|
/// Optionally give this offload task a name for any tasklist.
|
|
|
|
string_view name;
|
|
|
|
|
|
|
|
/// The function will be executed on each thread.
|
|
|
|
size_t concurrency {1};
|
|
|
|
|
|
|
|
/// Queuing priority; in the form of a nice value.
|
|
|
|
int8_t prio {0};
|
|
|
|
};
|
|
|
|
|
2017-08-28 23:51:22 +02:00
|
|
|
struct ircd::ctx::ole::init
|
2016-09-27 10:40:33 +02:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
~init() noexcept;
|
|
|
|
};
|