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

ircd::fpe: Inline errors_handle; minor include reorder.

This commit is contained in:
Jason Volk 2020-06-18 01:01:23 -07:00
parent 59829f1a59
commit b08e161e27
3 changed files with 51 additions and 45 deletions

View file

@ -19,6 +19,7 @@ namespace ircd::fpe
string_view reflect(const ushort &flag);
string_view reflect(const mutable_buffer &, const ushort &flags);
[[noreturn]] void _throw_errors(const ushort &flags);
void throw_errors(const ushort &flags);
std::fexcept_t set(const ushort &flag);
}
@ -38,3 +39,48 @@ struct ircd::fpe::errors_handle
errors_handle();
~errors_handle() noexcept(false);
};
[[gnu::always_inline]] inline
ircd::fpe::errors_handle::errors_handle()
{
syscall(std::fegetexceptflag, &theirs, FE_ALL_EXCEPT);
clear_pending();
}
[[gnu::always_inline]] inline
ircd::fpe::errors_handle::~errors_handle()
noexcept(false)
{
const unwind reset{[this]
{
syscall(std::fesetexceptflag, &theirs, FE_ALL_EXCEPT);
}};
throw_pending();
}
inline void
ircd::fpe::errors_handle::clear_pending()
{
syscall(std::feclearexcept, FE_ALL_EXCEPT);
}
inline void
ircd::fpe::errors_handle::throw_pending()
const
{
const auto pending
{
this->pending()
};
if(unlikely(pending))
_throw_errors(pending);
}
inline ushort
ircd::fpe::errors_handle::pending()
const
{
return std::fetestexcept(FE_ALL_EXCEPT);
}

View file

@ -52,14 +52,15 @@
#include "run.h"
#include "demangle.h"
#include "backtrace.h"
#include "fpe.h"
#include "locale.h"
#include "time.h"
#include "lex_cast.h"
#include "logger.h"
#include "info.h"
#include "sys.h"
#include "fpe.h"
#include "rand.h"
#include "crh.h"
#include "lex_cast.h"
#include "base.h"
#include "stringops.h"
#include "strl.h"
@ -84,7 +85,6 @@
#include "conf.h"
#include "magic.h"
#include "stats.h"
#include "sys.h"
#include "prof/prof.h"
#include "fs/fs.h"
#include "ios.h"

View file

@ -21,11 +21,9 @@ ircd::fpe::set(const ushort &flags)
}
void
ircd::fpe::throw_errors(const ushort &flags)
ircd::fpe::_throw_errors(const ushort &flags)
{
if(!flags)
return;
assert(flags);
thread_local char buf[128];
throw std::domain_error
{
@ -88,41 +86,3 @@ ircd::fpe::reflect_sicode(const int &code)
return "?????";
}
//
// errors_handle
//
ircd::fpe::errors_handle::errors_handle()
{
syscall(std::fegetexceptflag, &theirs, FE_ALL_EXCEPT);
clear_pending();
}
ircd::fpe::errors_handle::~errors_handle()
noexcept(false)
{
const auto pending(this->pending());
syscall(std::fesetexceptflag, &theirs, FE_ALL_EXCEPT);
throw_errors(pending);
}
void
ircd::fpe::errors_handle::clear_pending()
{
syscall(std::feclearexcept, FE_ALL_EXCEPT);
}
void
ircd::fpe::errors_handle::throw_pending()
const
{
throw_errors(pending());
}
ushort
ircd::fpe::errors_handle::pending()
const
{
return std::fetestexcept(FE_ALL_EXCEPT);
}