mirror of
https://github.com/matrix-construct/construct
synced 2024-07-02 00:38:24 +02:00
ircd::ctx: Move ctx headers into directory.
This commit is contained in:
parent
e6c8025ae0
commit
2f645941a8
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include <ircd/ircd.h>
|
#include <ircd/ircd.h>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <ircd/ctx_ctx.h>
|
#include <ircd/ctx/ctx.h>
|
||||||
#include "lgetopt.h"
|
#include "lgetopt.h"
|
||||||
|
|
||||||
namespace path = ircd::path;
|
namespace path = ircd::path;
|
||||||
|
|
|
@ -25,7 +25,23 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#define HAVE_IRCD_CTX_H
|
#define HAVE_IRCD_CTX_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
//
|
||||||
|
// This is the public interface to the userspace context system. No 3rd party
|
||||||
|
// symbols are included from here. This file is included automatically in stdinc.h
|
||||||
|
// and you do not have to include it manually.
|
||||||
|
//
|
||||||
|
// There are two primary objects at work in the context system:
|
||||||
|
//
|
||||||
|
// `struct context` <ircd/ctx/context.h>
|
||||||
|
// Public interface emulating std::thread; included automatically from here.
|
||||||
|
// To spawn and manipulate contexts, deal with this object.
|
||||||
|
//
|
||||||
|
// `struct ctx` <ircd/ctx/ctx.h>
|
||||||
|
// Internal implementation of the context and state holder. This is not included here.
|
||||||
|
// Several low-level functions are exposed for library creators. This file is usually
|
||||||
|
// included when boost/asio.hpp is also included and calls are actually made into boost.
|
||||||
|
//
|
||||||
|
|
||||||
namespace ircd {
|
namespace ircd {
|
||||||
namespace ctx {
|
namespace ctx {
|
||||||
|
|
||||||
|
@ -80,71 +96,55 @@ void sleep_until(const time_point &tp);
|
||||||
template<class duration> void sleep(const duration &);
|
template<class duration> void sleep(const duration &);
|
||||||
void sleep(const int &secs);
|
void sleep(const int &secs);
|
||||||
|
|
||||||
class context
|
} // namespace ctx
|
||||||
{
|
|
||||||
std::unique_ptr<ctx> c;
|
|
||||||
|
|
||||||
public:
|
using ctx::timeout;
|
||||||
bool operator!() const { return !c; }
|
|
||||||
operator bool() const { return bool(c); }
|
|
||||||
|
|
||||||
operator const ctx &() const { return *c; }
|
} // namespace ircd
|
||||||
operator ctx &() { return *c; }
|
|
||||||
|
|
||||||
bool joined() const { return !c || ircd::ctx::finished(*c); }
|
#include "ctx/context.h"
|
||||||
void interrupt() { ircd::ctx::interrupt(*c); }
|
#include "ctx/prof.h"
|
||||||
void join(); // Blocks the current context until this one finishes
|
#include "ctx/dock.h"
|
||||||
ctx *detach(); // other calls undefined after this call
|
#include "ctx/mutex.h"
|
||||||
|
#include "ctx/shared_state.h"
|
||||||
// Note: Constructing with SELF_DESTRUCT flag makes any further use of this object undefined.
|
#include "ctx/promise.h"
|
||||||
context(const size_t &stack_size, std::function<void ()>, const enum flags &flags = (enum flags)0);
|
#include "ctx/future.h"
|
||||||
context(std::function<void ()>, const enum flags &flags = (enum flags)0);
|
#include "ctx/async.h"
|
||||||
context(context &&) noexcept = default;
|
#include "ctx/pool.h"
|
||||||
context(const context &) = delete;
|
#include "ctx/ole.h"
|
||||||
~context() noexcept;
|
|
||||||
|
|
||||||
friend void swap(context &a, context &b) noexcept;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
swap(context &a, context &b)
|
ircd::ctx::sleep(const int &secs)
|
||||||
noexcept
|
|
||||||
{
|
|
||||||
std::swap(a.c, b.c);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void
|
|
||||||
sleep(const int &secs)
|
|
||||||
{
|
{
|
||||||
sleep(seconds(secs));
|
sleep(seconds(secs));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class duration>
|
template<class duration>
|
||||||
void
|
void
|
||||||
sleep(const duration &d)
|
ircd::ctx::sleep(const duration &d)
|
||||||
{
|
{
|
||||||
sleep_until(steady_clock::now() + d);
|
sleep_until(steady_clock::now() + d);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class E>
|
template<class E>
|
||||||
throw_overload<E>
|
ircd::throw_overload<E>
|
||||||
wait_until(const time_point &tp)
|
ircd::ctx::wait_until(const time_point &tp)
|
||||||
{
|
{
|
||||||
if(wait_until<std::nothrow_t>(tp))
|
if(wait_until<std::nothrow_t>(tp))
|
||||||
throw E();
|
throw E();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class E>
|
template<class E>
|
||||||
nothrow_overload<E, bool>
|
ircd::nothrow_overload<E, bool>
|
||||||
wait_until(const time_point &tp)
|
ircd::ctx::wait_until(const time_point &tp)
|
||||||
{
|
{
|
||||||
return wait_until(tp, std::nothrow);
|
return wait_until(tp, std::nothrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class E,
|
template<class E,
|
||||||
class duration>
|
class duration>
|
||||||
throw_overload<E, duration>
|
ircd::throw_overload<E, duration>
|
||||||
wait(const duration &d)
|
ircd::ctx::wait(const duration &d)
|
||||||
{
|
{
|
||||||
const auto ret(wait<std::nothrow_t>(d));
|
const auto ret(wait<std::nothrow_t>(d));
|
||||||
return ret <= duration(0)? throw E() : ret;
|
return ret <= duration(0)? throw E() : ret;
|
||||||
|
@ -152,8 +152,8 @@ wait(const duration &d)
|
||||||
|
|
||||||
template<class E,
|
template<class E,
|
||||||
class duration>
|
class duration>
|
||||||
nothrow_overload<E, duration>
|
ircd::nothrow_overload<E, duration>
|
||||||
wait(const duration &d)
|
ircd::ctx::wait(const duration &d)
|
||||||
{
|
{
|
||||||
using std::chrono::duration_cast;
|
using std::chrono::duration_cast;
|
||||||
|
|
||||||
|
@ -161,17 +161,9 @@ wait(const duration &d)
|
||||||
return duration_cast<duration>(ret);
|
return duration_cast<duration>(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline ctx &
|
inline ircd::ctx::ctx &
|
||||||
cur()
|
ircd::ctx::cur()
|
||||||
{
|
{
|
||||||
assert(current);
|
assert(current);
|
||||||
return *current;
|
return *current;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ctx
|
|
||||||
|
|
||||||
using ctx::context;
|
|
||||||
using ctx::timeout;
|
|
||||||
|
|
||||||
} // namespace ircd
|
|
||||||
#endif // __cplusplus
|
|
||||||
|
|
68
include/ircd/ctx/context.h
Normal file
68
include/ircd/ctx/context.h
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* charybdis: oh just a little chat server
|
||||||
|
* ctx.h: userland context switching (stackful coroutines)
|
||||||
|
*
|
||||||
|
* Copyright (C) 2016 Charybdis Development Team
|
||||||
|
* Copyright (C) 2016 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.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||||
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#define HAVE_IRCD_CTX_CONTEXT_H
|
||||||
|
|
||||||
|
namespace ircd {
|
||||||
|
namespace ctx {
|
||||||
|
|
||||||
|
class context
|
||||||
|
{
|
||||||
|
std::unique_ptr<ctx> c;
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool operator!() const { return !c; }
|
||||||
|
operator bool() const { return bool(c); }
|
||||||
|
|
||||||
|
operator const ctx &() const { return *c; }
|
||||||
|
operator ctx &() { return *c; }
|
||||||
|
|
||||||
|
bool joined() const { return !c || ircd::ctx::finished(*c); }
|
||||||
|
void interrupt() { ircd::ctx::interrupt(*c); }
|
||||||
|
void join(); // Blocks the current context until this one finishes
|
||||||
|
ctx *detach(); // other calls undefined after this call
|
||||||
|
|
||||||
|
// Note: Constructing with SELF_DESTRUCT flag makes any further use of this object undefined.
|
||||||
|
context(const size_t &stack_size, std::function<void ()>, const enum flags &flags = (enum flags)0);
|
||||||
|
context(std::function<void ()>, const enum flags &flags = (enum flags)0);
|
||||||
|
context(context &&) noexcept = default;
|
||||||
|
context(const context &) = delete;
|
||||||
|
~context() noexcept;
|
||||||
|
|
||||||
|
friend void swap(context &a, context &b) noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline void
|
||||||
|
swap(context &a, context &b)
|
||||||
|
noexcept
|
||||||
|
{
|
||||||
|
std::swap(a.c, b.c);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ctx
|
||||||
|
|
||||||
|
using ctx::context;
|
||||||
|
|
||||||
|
} // namespace ircd
|
|
@ -26,7 +26,7 @@
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/asio/steady_timer.hpp>
|
#include <boost/asio/steady_timer.hpp>
|
||||||
#include "bufs.h"
|
#include "bufs.h"
|
||||||
#include "ctx_ctx.h"
|
#include "ctx/ctx.h"
|
||||||
|
|
||||||
namespace ircd {
|
namespace ircd {
|
||||||
|
|
||||||
|
|
|
@ -91,15 +91,6 @@ namespace ircd
|
||||||
#include "mode_lease.h"
|
#include "mode_lease.h"
|
||||||
#include "snomask.h"
|
#include "snomask.h"
|
||||||
#include "ctx.h"
|
#include "ctx.h"
|
||||||
#include "ctx_prof.h"
|
|
||||||
#include "ctx_dock.h"
|
|
||||||
#include "ctx_mutex.h"
|
|
||||||
#include "ctx_shared_state.h"
|
|
||||||
#include "ctx_promise.h"
|
|
||||||
#include "ctx_future.h"
|
|
||||||
#include "ctx_async.h"
|
|
||||||
#include "ctx_pool.h"
|
|
||||||
#include "ctx_ole.h"
|
|
||||||
#include "hook.h"
|
#include "hook.h"
|
||||||
#include "line.h"
|
#include "line.h"
|
||||||
#include "tape.h"
|
#include "tape.h"
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ircd/ctx_ctx.h>
|
#include <ircd/ctx/ctx.h>
|
||||||
|
|
||||||
using namespace ircd;
|
using namespace ircd;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <ircd/ctx_ctx.h>
|
#include <ircd/ctx/ctx.h>
|
||||||
#include <ircd/js.h>
|
#include <ircd/js.h>
|
||||||
|
|
||||||
namespace ircd
|
namespace ircd
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <ircd/ctx_ctx.h>
|
#include <ircd/ctx/ctx.h>
|
||||||
#include <ircd/lex_cast.h>
|
#include <ircd/lex_cast.h>
|
||||||
#include <ircd/sock.h>
|
#include <ircd/sock.h>
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <ircd/ctx_ctx.h>
|
#include <ircd/ctx/ctx.h>
|
||||||
|
|
||||||
namespace ip = boost::asio::ip;
|
namespace ip = boost::asio::ip;
|
||||||
using namespace ircd;
|
using namespace ircd;
|
||||||
|
|
Loading…
Reference in a new issue