5#ifndef WPINET_UV_ASYNC_H_
6#define WPINET_UV_ASYNC_H_
35template <
typename... T>
37 struct private_init {};
40 Async(
const std::shared_ptr<Loop>& loop,
const private_init&)
43 if (
auto loop = m_loop.lock()) {
56 return Create(loop.shared_from_this());
64 static std::shared_ptr<Async>
Create(
const std::shared_ptr<Loop>& loop) {
65 if (loop->IsClosing()) {
68 auto h = std::make_shared<Async>(loop, private_init{});
71 auto& h = *static_cast<Async*>(handle->data);
72 std::scoped_lock lock(h.m_mutex);
73 for (auto&& v : h.m_data) {
74 std::apply(h.wakeup, v);
79 loop->ReportError(err);
92 template <
typename... U>
94 auto loop = m_loop.lock();
95 if (loop->IsClosing()) {
98 if (loop && loop->GetThreadId() == std::this_thread::get_id()) {
100 wakeup(std::forward<U>(u)...);
105 std::scoped_lock lock(m_mutex);
106 m_data.emplace_back(std::forward_as_tuple(std::forward<U>(u)...));
129 std::vector<std::tuple<T...>> m_data;
130 std::weak_ptr<Loop> m_loop;
139 struct private_init {};
142 Async(
const std::shared_ptr<Loop>& loop,
const private_init&)
152 return Create(loop.shared_from_this());
160 static std::shared_ptr<Async>
Create(
const std::shared_ptr<Loop>& loop);
169 if (
auto loop = m_loop.lock()) {
170 if (loop->IsClosing()) {
173 if (loop->GetThreadId() == std::this_thread::get_id()) {
197 std::weak_ptr<Loop> m_loop;
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495
sig::Signal wakeup
Signal generated (on event loop thread) when the async event occurs.
Definition: Async.h:194
void UnsafeSend()
Wakeup the event loop and emit the event.
Definition: Async.h:189
void Send()
Wakeup the event loop and emit the event.
Definition: Async.h:168
static std::shared_ptr< Async > Create(const std::shared_ptr< Loop > &loop)
Create an async handle.
~Async() noexcept override
Async(const std::shared_ptr< Loop > &loop, const private_init &)
Definition: Async.h:142
Async handle.
Definition: Async.h:36
void Send(U &&... u)
Wakeup the event loop and emit the event.
Definition: Async.h:93
static std::shared_ptr< Async > Create(const std::shared_ptr< Loop > &loop)
Create an async handle.
Definition: Async.h:64
~Async() noexcept override
Definition: Async.h:42
static std::shared_ptr< Async > Create(Loop &loop)
Create an async handle.
Definition: Async.h:55
void UnsafeSend()
Wakeup the event loop and emit the event.
Definition: Async.h:120
Async(const std::shared_ptr< Loop > &loop, const private_init &)
Definition: Async.h:40
sig::Signal< T... > wakeup
Signal generated (on event loop thread) when the async event occurs.
Definition: Async.h:125
void ForceClosed() noexcept
Definition: Handle.h:245
void Close() noexcept
Request handle to be closed.
Handle.
Definition: Handle.h:273
Event loop.
Definition: Loop.h:37
std::vector< uint8_t > GetRaw(NT_Handle subentry, std::span< const uint8_t > defaultValue)
Get the last published value.
Definition: StdDeque.h:50
static constexpr const unit_t< compound_unit< energy::joule, time::seconds > > h(6.626070040e-34)
Planck constant.
Definition: ParallelTcpConnector.h:22
::std::mutex mutex
Definition: mutex.h:17
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)