mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 10:12:39 +01:00
ircd::ctx: Cleanup / fixes for critical assertion related.
This commit is contained in:
parent
339940ddfc
commit
c74debac01
3 changed files with 31 additions and 7 deletions
|
@ -13,7 +13,7 @@
|
|||
|
||||
namespace ircd::ctx::this_ctx
|
||||
{
|
||||
struct critical_assertion; // Assert no yielding for a section
|
||||
struct critical_assertion; // Assert no yielding for a section
|
||||
}
|
||||
|
||||
/// An instance of critical_assertion detects an attempt to context switch.
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
namespace ircd::ctx::this_ctx
|
||||
{
|
||||
struct critical_indicator; // Indicates if yielding happened for a section
|
||||
struct critical_indicator; // Indicates if yielding happened for a section
|
||||
}
|
||||
|
||||
/// An instance of critical_indicator reports if context switching happened.
|
||||
|
|
34
ircd/ctx.cc
34
ircd/ctx.cc
|
@ -717,47 +717,69 @@ noexcept
|
|||
//
|
||||
// critical_assertion
|
||||
//
|
||||
#ifndef NDEBUG
|
||||
|
||||
namespace ircd::ctx
|
||||
{
|
||||
bool critical_asserted;
|
||||
|
||||
void assert_critical();
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
ircd::ctx::this_ctx::critical_assertion::critical_assertion()
|
||||
:theirs{critical_asserted}
|
||||
{
|
||||
critical_asserted = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
ircd::ctx::this_ctx::critical_assertion::~critical_assertion()
|
||||
noexcept
|
||||
{
|
||||
assert(critical_asserted);
|
||||
critical_asserted = theirs;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NDEBUG
|
||||
#ifndef NDEBUG
|
||||
void
|
||||
ircd::ctx::assert_critical()
|
||||
{
|
||||
if(unlikely(critical_asserted))
|
||||
throw ircd::assertive
|
||||
{
|
||||
"%lu '%s' :Illegal context switch", id(), name()
|
||||
};
|
||||
}
|
||||
#else
|
||||
void
|
||||
ircd::ctx::assert_critical()
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
//
|
||||
// stack_usage_assertion
|
||||
//
|
||||
#ifndef NDEBUG
|
||||
|
||||
#ifndef NDEBUG
|
||||
ircd::ctx::this_ctx::stack_usage_assertion::stack_usage_assertion()
|
||||
{
|
||||
const auto stack_usage(stack_at_here());
|
||||
assert(stack_usage < cur().stack.max * double(prof::settings::stack_usage_assertion));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NDEBUG
|
||||
ircd::ctx::this_ctx::stack_usage_assertion::~stack_usage_assertion()
|
||||
noexcept
|
||||
{
|
||||
const auto stack_usage(stack_at_here());
|
||||
assert(stack_usage < cur().stack.max * double(prof::settings::stack_usage_assertion));
|
||||
}
|
||||
|
||||
#endif // NDEBUG
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
@ -775,6 +797,8 @@ ircd::ctx::continuation::continuation()
|
|||
}
|
||||
{
|
||||
mark(prof::event::CUR_YIELD);
|
||||
|
||||
assert_critical();
|
||||
assert(!critical_asserted);
|
||||
assert(self != nullptr);
|
||||
assert(self->notes <= 1);
|
||||
|
|
Loading…
Reference in a new issue