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

ircd::ctx: Update stack allocator for official support. (boost-1.80)

This commit is contained in:
Jason Volk 2023-01-17 20:21:09 -08:00
parent c667987391
commit bb3576eaaa
3 changed files with 78 additions and 18 deletions

View file

@ -77,6 +77,7 @@ namespace boost
#include <boost/asio/detail/config.hpp>
#include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/context/stack_context.hpp>
#include <boost/coroutine/coroutine.hpp>
#if defined(BOOST_ASIO_HAS_EPOLL) \

View file

@ -8,6 +8,16 @@
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
namespace boost::context
{
struct stack_context;
}
namespace boost::coroutines
{
struct stack_context;
}
namespace ircd::ctx
{
struct stack;
@ -28,3 +38,16 @@ struct ircd::ctx::stack
static const stack &get(const ctx &) noexcept;
static stack &get(ctx &) noexcept;
};
struct [[gnu::visibility("hidden")]]
ircd::ctx::stack::allocator
{
mutable_buffer &buf;
bool owner {false};
void deallocate(boost::coroutines::stack_context &) noexcept;
void allocate(boost::coroutines::stack_context &, size_t size);
void deallocate(boost::context::stack_context &) noexcept;
boost::context::stack_context allocate();
};

View file

@ -143,7 +143,24 @@ ircd::ctx::ctx::spawn(context::function func)
ios::handler::leave(parent_handler);
assert(!ircd::ctx::current && !ios::handler::current);
boost::asio::spawn(ios::get(), ios::handle(ios_desc, std::move(bound)), attrs);
#if BOOST_VERSION >= 108000
boost::asio::spawn
(
ios::get(),
asio::allocator_arg_t{},
stack::allocator{stack.buf},
ios::handle{ios_desc, std::move(bound)},
asio::detached
);
#else
boost::asio::spawn
(
ios::get(),
ios::handle{ios_desc, std::move(bound)},
attrs
);
#endif
assert(!ircd::ctx::current && !ios::handler::current);
ios::handler::enter(parent_handler);
@ -3289,20 +3306,40 @@ noexcept
// stack::allocator
//
struct [[gnu::visibility("hidden")]]
ircd::ctx::stack::allocator
boost::context::stack_context
ircd::ctx::stack::allocator::allocate()
{
using stack_context = boost::coroutines::stack_context;
boost::coroutines::stack_context c;
allocate(c, std::distance(begin(buf), end(buf)));
mutable_buffer &buf;
bool owner {false};
return boost::context::stack_context
{
.size = c.size,
.sp = c.sp,
void allocate(stack_context &, size_t size);
void deallocate(stack_context &);
};
#if defined(BOOST_USE_VALGRIND)
.valgrind_stack_id = c.valgrind_stack_id,
#endif
};
}
void
ircd::ctx::stack::allocator::allocate(stack_context &c,
ircd::ctx::stack::allocator::deallocate(boost::context::stack_context &c)
noexcept
{
boost::coroutines::stack_context _c;
_c.size = c.size;
_c.sp = c.sp;
#if defined(BOOST_USE_VALGRIND)
_c.valgrind_stack_id = c.valgrind_stack_id;
#endif
deallocate(_c);
}
void
ircd::ctx::stack::allocator::allocate(boost::coroutines::stack_context &c,
size_t size)
{
static const auto &alignment
@ -3312,13 +3349,14 @@ ircd::ctx::stack::allocator::allocate(stack_context &c,
unique_mutable_buffer umb
{
null(this->buf)? size: 0, alignment
null(buf)? size: 0, alignment
};
const mutable_buffer &buf
if(umb)
{
umb? umb: this->buf
};
buf = umb.release();
this->owner = true;
}
c.size = ircd::size(buf);
c.sp = ircd::data(buf) + c.size;
@ -3327,13 +3365,11 @@ ircd::ctx::stack::allocator::allocate(stack_context &c,
if(vg::active)
c.valgrind_stack_id = vg::stack::add(buf);
#endif
this->owner = bool(umb);
this->buf = umb? umb.release(): this->buf;
}
void
ircd::ctx::stack::allocator::deallocate(stack_context &c)
ircd::ctx::stack::allocator::deallocate(boost::coroutines::stack_context &c)
noexcept
{
assert(c.sp);