0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-26 22:08:20 +02: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/config.hpp>
#include <boost/asio/detail/socket_types.hpp> #include <boost/asio/detail/socket_types.hpp>
#include <boost/asio/ssl/detail/openssl_types.hpp> #include <boost/asio/ssl/detail/openssl_types.hpp>
#include <boost/context/stack_context.hpp>
#include <boost/coroutine/coroutine.hpp> #include <boost/coroutine/coroutine.hpp>
#if defined(BOOST_ASIO_HAS_EPOLL) \ #if defined(BOOST_ASIO_HAS_EPOLL) \

View file

@ -8,6 +8,16 @@
// copyright notice and this permission notice is present in all copies. The // copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file. // 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 namespace ircd::ctx
{ {
struct stack; struct stack;
@ -28,3 +38,16 @@ struct ircd::ctx::stack
static const stack &get(const ctx &) noexcept; static const stack &get(const ctx &) noexcept;
static stack &get(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); ios::handler::leave(parent_handler);
assert(!ircd::ctx::current && !ios::handler::current); 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); assert(!ircd::ctx::current && !ios::handler::current);
ios::handler::enter(parent_handler); ios::handler::enter(parent_handler);
@ -3289,20 +3306,40 @@ noexcept
// stack::allocator // stack::allocator
// //
struct [[gnu::visibility("hidden")]] boost::context::stack_context
ircd::ctx::stack::allocator 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; return boost::context::stack_context
bool owner {false}; {
.size = c.size,
.sp = c.sp,
void allocate(stack_context &, size_t size); #if defined(BOOST_USE_VALGRIND)
void deallocate(stack_context &); .valgrind_stack_id = c.valgrind_stack_id,
}; #endif
};
}
void 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) size_t size)
{ {
static const auto &alignment static const auto &alignment
@ -3312,13 +3349,14 @@ ircd::ctx::stack::allocator::allocate(stack_context &c,
unique_mutable_buffer umb 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.size = ircd::size(buf);
c.sp = ircd::data(buf) + c.size; c.sp = ircd::data(buf) + c.size;
@ -3327,13 +3365,11 @@ ircd::ctx::stack::allocator::allocate(stack_context &c,
if(vg::active) if(vg::active)
c.valgrind_stack_id = vg::stack::add(buf); c.valgrind_stack_id = vg::stack::add(buf);
#endif #endif
this->owner = bool(umb);
this->buf = umb? umb.release(): this->buf;
} }
void void
ircd::ctx::stack::allocator::deallocate(stack_context &c) ircd::ctx::stack::allocator::deallocate(boost::coroutines::stack_context &c)
noexcept
{ {
assert(c.sp); assert(c.sp);