Skip to content

Commit

Permalink
broader definition of ipi_call() function
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenny committed Dec 9, 2018
1 parent 29e23b1 commit 38d97b0
Showing 1 changed file with 10 additions and 24 deletions.
34 changes: 10 additions & 24 deletions src/hvpp/hvpp/lib/mp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,21 @@ namespace mp
inline void sleep(uint32_t milliseconds) noexcept
{ detail::sleep(milliseconds); }

//
// Inter-Processor Interrupt - runs specified method on all logical CPUs.
//

inline void ipi_call(void(*callback)(void*), void* context) noexcept
{ detail::ipi_call(callback, context); }

inline void ipi_call(void(*callback)()) noexcept
{ detail::ipi_call([](void* context) { ((void(*)())context)(); }, callback); }

template <
typename T
>
template <typename T>
inline void ipi_call(T function) noexcept
{ ipi_call([](void* context) noexcept { ((T*)context)->operator()(); }, &function); }

template <typename T>
inline void ipi_call(T* instance, void (T::*member_function)()) noexcept
{
//
// Inter-Processor Interrupt - runs specified method on all logical CPUs.
//
struct ipi_ctx
{
T* instance;
void (T::*member_function)();
} ipi_context {
instance,
member_function
};

ipi_call([](void* context) noexcept {
auto ipi_context = reinterpret_cast<ipi_ctx*>(context);
auto instance = ipi_context->instance;
auto member_function = ipi_context->member_function;

(instance->*member_function)();
}, &ipi_context);
}
{ ipi_call([=]() { (instance->*member_function)(); }); }
}

0 comments on commit 38d97b0

Please sign in to comment.