33template <
typename... T>
35 struct private_init {};
38 Async(
const std::shared_ptr<Loop>&
loop,
const private_init&)
41 if (
auto loop = m_loop.lock()) {
62 static std::shared_ptr<Async>
Create(
const std::shared_ptr<Loop>&
loop) {
63 if (
loop->IsClosing()) {
66 auto h = std::make_shared<Async>(
loop, private_init{});
69 auto& h = *static_cast<Async*>(handle->data);
70 std::scoped_lock lock(h.m_mutex);
71 for (auto&& v : h.m_data) {
72 std::apply(h.wakeup, v);
90 template <
typename... U>
92 auto loop = m_loop.lock();
93 if (
loop->IsClosing()) {
96 if (
loop &&
loop->GetThreadId() == std::this_thread::get_id()) {
98 wakeup(std::forward<U>(u)...);
103 std::scoped_lock lock(m_mutex);
104 m_data.emplace_back(std::forward_as_tuple(std::forward<U>(u)...));
127 std::vector<std::tuple<T...>> m_data;
128 std::weak_ptr<Loop> m_loop;
137 struct private_init {};
140 Async(
const std::shared_ptr<Loop>&
loop,
const private_init&)
158 static std::shared_ptr<Async>
Create(
const std::shared_ptr<Loop>&
loop);
167 if (
auto loop = m_loop.lock()) {
168 if (
loop->IsClosing()) {
171 if (
loop->GetThreadId() == std::this_thread::get_id()) {
195 std::weak_ptr<Loop> m_loop;
Async(const std::shared_ptr< Loop > &loop, const private_init &)
Definition Async.hpp:140
void Send()
Wakeup the event loop and emit the event.
Definition Async.hpp:166
static std::shared_ptr< Async > Create(const std::shared_ptr< Loop > &loop)
Create an async handle.
wpi::util::sig::Signal wakeup
Signal generated (on event loop thread) when the async event occurs.
Definition Async.hpp:192
void UnsafeSend()
Wakeup the event loop and emit the event.
Definition Async.hpp:187
static std::shared_ptr< Async > Create(Loop &loop)
Create an async handle.
Definition Async.hpp:149
~Async() noexcept override
static std::shared_ptr< Async > Create(const std::shared_ptr< Loop > &loop)
Create an async handle.
Definition Async.hpp:62
~Async() noexcept override
Definition Async.hpp:40
void UnsafeSend()
Wakeup the event loop and emit the event.
Definition Async.hpp:118
static std::shared_ptr< Async > Create(Loop &loop)
Create an async handle.
Definition Async.hpp:53
wpi::util::sig::Signal< T... > wakeup
Signal generated (on event loop thread) when the async event occurs.
Definition Async.hpp:123
void Send(U &&... u)
Wakeup the event loop and emit the event.
Definition Async.hpp:91
Async(const std::shared_ptr< Loop > &loop, const private_init &)
Definition Async.hpp:38
void ForceClosed() noexcept
Definition Handle.hpp:259
bool Invoke(F &&f, Args &&... args) const
Definition Handle.hpp:265
void Close() noexcept
Request handle to be closed.
uv_async_t * GetRaw() const noexcept
Definition Handle.hpp:303
HandleImpl()
Definition Handle.hpp:308
Event loop.
Definition Loop.hpp:35
Definition StringMap.hpp:773
Definition Errors.hpp:112
Definition Prepare.hpp:14
SignalBase< detail::NullMutex, T... > Signal
Specialization of SignalBase to be used in single threaded contexts.
Definition Signal.h:809
::std::mutex mutex
Definition mutex.hpp:17
struct uv_async_s uv_async_t
Definition uv.h:228
UV_EXTERN int uv_async_init(uv_loop_t *, uv_async_t *async, uv_async_cb async_cb)
UV_EXTERN int uv_async_send(uv_async_t *async)