8 #ifndef WPIUTIL_WPI_UV_ASYNC_H_
9 #define WPIUTIL_WPI_UV_ASYNC_H_
18 #include "wpi/STLExtras.h"
19 #include "wpi/Signal.h"
20 #include "wpi/mutex.h"
21 #include "wpi/uv/Handle.h"
22 #include "wpi/uv/Loop.h"
38 template <
typename... T>
40 struct private_init {};
43 explicit Async(
const private_init&) {}
44 ~
Async() noexcept
override =
default;
52 auto h = std::make_shared<Async>(private_init{});
54 auto& h = *
static_cast<Async*
>(handle->data);
55 std::lock_guard<wpi::mutex> lock(h.m_mutex);
72 static std::shared_ptr<Async>
Create(
const std::shared_ptr<Loop>& loop) {
82 template <
typename... U>
85 std::lock_guard<wpi::mutex> lock(m_mutex);
86 m_data.emplace_back(std::forward_as_tuple(std::forward<U>(u)...));
88 this->Invoke(&uv_async_send, this->
GetRaw());
98 std::vector<std::tuple<T...>> m_data;
107 struct private_init {};
110 explicit Async(
const private_init&) {}
111 ~
Async() noexcept
override =
default;
118 static std::shared_ptr<Async>
Create(
Loop& loop);
125 static std::shared_ptr<Async>
Create(
const std::shared_ptr<Loop>& loop) {
146 #endif // WPIUTIL_WPI_UV_ASYNC_H_
uv_async_t * GetRaw() const noexcept
Get the underlying handle data structure.
Definition: Handle.h:261
sig::Signal wakeup
Signal generated (on event loop thread) when the async event occurs.
Definition: Async.h:140
Handle.
Definition: Handle.h:246
void ReportError(int err)
Reports error.
Definition: Loop.h:235
uv_loop_t * GetRaw() const noexcept
Get the underlying event loop data structure.
Definition: Loop.h:209
WPILib C++ utilities (wpiutil) namespace.
Definition: SmallString.h:21
static std::shared_ptr< Async > Create(Loop &loop)
Create an async handle.
Definition: Async.h:51
void Send()
Wakeup the event loop and emit the event.
Definition: Async.h:135
auto apply_tuple(F &&f, Tuple &&t) -> decltype(detail::apply_tuple_impl(std::forward< F >(f), std::forward< Tuple >(t), build_index_impl< std::tuple_size< typename std::decay< Tuple >::type >::value >
Given an input tuple (a1, a2, ..., an), pass the arguments of the tuple variadically to f as if by ca...
Definition: STLExtras.h:1209
sig::Signal< T...> wakeup
Signal generated (on event loop thread) when the async event occurs.
Definition: Async.h:94
static std::shared_ptr< Async > Create(const std::shared_ptr< Loop > &loop)
Create an async handle.
Definition: Async.h:125
static std::shared_ptr< Async > Create(const std::shared_ptr< Loop > &loop)
Create an async handle.
Definition: Async.h:72
Event loop.
Definition: Loop.h:37
void Send(U &&...u)
Wakeup the event loop and emit the event.
Definition: Async.h:83
Async handle.
Definition: Async.h:39
SignalBase is an implementation of the observer pattern, through the use of an emitting object and sl...
Definition: Signal.h:495