0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 18:18:56 +02:00

ircd::ctx: Cleanup / fixes for critical assertion related.

This commit is contained in:
Jason Volk 2018-11-29 16:12:33 -08:00
parent 339940ddfc
commit c74debac01
3 changed files with 31 additions and 7 deletions

View file

@ -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.

View file

@ -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.

View file

@ -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);