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

ircd::ctx::posix: Reduce decisionals to static util; minor cleanup.

This commit is contained in:
Jason Volk 2020-05-05 20:42:48 -07:00
parent 72ae3073d3
commit 598bbc45cc

View file

@ -23,8 +23,10 @@
namespace ircd::ctx::posix namespace ircd::ctx::posix
{ {
static bool is(const pthread_t &) noexcept;
extern std::vector<context> ctxs;
extern log::log log; extern log::log log;
std::vector<context> ctxs;
} }
using ircd::always_assert; using ircd::always_assert;
@ -35,6 +37,9 @@ ircd::ctx::posix::log
"ctx.posix" "ctx.posix"
}; };
decltype(ircd::ctx::posix::ctxs)
ircd::ctx::posix::ctxs;
// //
// Linker wraps/hooks; see ircd/Makefile.am LDFLAGS. These allow us to play // Linker wraps/hooks; see ircd/Makefile.am LDFLAGS. These allow us to play
// nice with legitimate uses of pthreads by the rest of the address space by // nice with legitimate uses of pthreads by the rest of the address space by
@ -81,7 +86,7 @@ extern "C" int
__wrap_pthread_join(pthread_t __th, __wrap_pthread_join(pthread_t __th,
void **__thread_return) void **__thread_return)
{ {
return ircd::ctx::current? return ircd::ctx::posix::is(__th)?
ircd_pthread_join(__th, __thread_return): ircd_pthread_join(__th, __thread_return):
__real_pthread_join(__th, __thread_return); __real_pthread_join(__th, __thread_return);
} }
@ -105,16 +110,7 @@ __wrap_pthread_timedjoin_np(pthread_t __th,
void **__thread_return, void **__thread_return,
const struct timespec *__abstime) const struct timespec *__abstime)
{ {
const auto it return ircd::ctx::posix::is(__th)?
{
std::find_if(begin(ircd::ctx::posix::ctxs), end(ircd::ctx::posix::ctxs), [&]
(const auto &context)
{
return ircd::ctx::id(context) == __th;
})
};
return it != end(ircd::ctx::posix::ctxs)?
ircd_pthread_timedjoin_np(__th, __thread_return, __abstime): ircd_pthread_timedjoin_np(__th, __thread_return, __abstime):
__real_pthread_timedjoin_np(__th, __thread_return, __abstime); __real_pthread_timedjoin_np(__th, __thread_return, __abstime);
} }
@ -158,16 +154,7 @@ extern "C" int
__wrap_pthread_setname_np(pthread_t __target_thread, __wrap_pthread_setname_np(pthread_t __target_thread,
const char *__name) const char *__name)
{ {
const auto it return ircd::ctx::posix::is(__target_thread)?
{
std::find_if(begin(ircd::ctx::posix::ctxs), end(ircd::ctx::posix::ctxs), [&]
(const auto &context)
{
return ircd::ctx::id(context) == __target_thread;
})
};
return it != end(ircd::ctx::posix::ctxs)?
ircd_pthread_setname_np(__target_thread, __name): ircd_pthread_setname_np(__target_thread, __name):
__real_pthread_setname_np(__target_thread, __name); __real_pthread_setname_np(__target_thread, __name);
} }
@ -177,6 +164,26 @@ pthread_setname_np(pthread_t __target_thread,
const char *__name) const char *__name)
__attribute__((weak, alias("__wrap_pthread_setname_np"))); __attribute__((weak, alias("__wrap_pthread_setname_np")));
//
// util
//
bool
ircd::ctx::posix::is(const pthread_t &target)
noexcept
{
const auto it
{
std::find_if(begin(ctxs), end(ctxs), [&]
(const auto &context)
{
return id(context) == target;
})
};
return it != end(ctxs);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// //
// pthread supplement // pthread supplement