mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
ircd::ctx::posix: Reduce decisionals to static util; minor cleanup.
This commit is contained in:
parent
72ae3073d3
commit
598bbc45cc
1 changed files with 29 additions and 22 deletions
|
@ -23,8 +23,10 @@
|
|||
|
||||
namespace ircd::ctx::posix
|
||||
{
|
||||
static bool is(const pthread_t &) noexcept;
|
||||
|
||||
extern std::vector<context> ctxs;
|
||||
extern log::log log;
|
||||
std::vector<context> ctxs;
|
||||
}
|
||||
|
||||
using ircd::always_assert;
|
||||
|
@ -35,6 +37,9 @@ ircd::ctx::posix::log
|
|||
"ctx.posix"
|
||||
};
|
||||
|
||||
decltype(ircd::ctx::posix::ctxs)
|
||||
ircd::ctx::posix::ctxs;
|
||||
|
||||
//
|
||||
// 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
|
||||
|
@ -81,7 +86,7 @@ extern "C" int
|
|||
__wrap_pthread_join(pthread_t __th,
|
||||
void **__thread_return)
|
||||
{
|
||||
return ircd::ctx::current?
|
||||
return ircd::ctx::posix::is(__th)?
|
||||
ircd_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,
|
||||
const struct timespec *__abstime)
|
||||
{
|
||||
const auto it
|
||||
{
|
||||
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)?
|
||||
return ircd::ctx::posix::is(__th)?
|
||||
ircd_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,
|
||||
const char *__name)
|
||||
{
|
||||
const auto it
|
||||
{
|
||||
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)?
|
||||
return ircd::ctx::posix::is(__target_thread)?
|
||||
ircd_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)
|
||||
__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
|
||||
|
|
Loading…
Reference in a new issue