34class Loop final :
public std::enable_shared_from_this<Loop> {
35 struct private_init {};
38 using Time = std::chrono::duration<uint64_t, std::milli>;
46 explicit Loop(
const private_init&)
noexcept;
109 m_tid = std::this_thread::get_id();
111 m_tid = std::thread::id{};
152 return std::pair{to == -1,
Time{to}};
228 template <
typename T =
void>
230 return std::static_pointer_cast<T>(m_data);
237 void SetData(std::shared_ptr<void> data) { m_data = std::move(data); }
257 std::shared_ptr<void> m_data;
260 std::atomic<std::thread::id> m_tid;
261 bool m_closing =
false;
Handle.
Definition Handle.hpp:32
std::thread::id GetThreadId() const
Get the thread id of the loop thread.
Definition Loop.hpp:243
bool IsClosing() const
Return the loop closed flag.
Definition Loop.hpp:82
void UpdateTime() noexcept
Update the event loop’s concept of now.
Definition Loop.hpp:178
bool IsAlive() const noexcept
Check if there are active resources.
Definition Loop.hpp:120
void SetClosing()
Set the loop closing flag.
Definition Loop.hpp:75
Loop(const private_init &) noexcept
void Close()
Release all internal loop resources.
void SetData(std::shared_ptr< void > data)
Sets user-defined data.
Definition Loop.hpp:237
bool Run(Mode mode=Mode::DEFAULT)
Run the event loop.
Definition Loop.hpp:108
Time Now() const noexcept
Return the current timestamp in milliseconds.
Definition Loop.hpp:167
static std::shared_ptr< Loop > GetDefault()
Create the default event loop.
void Walk(wpi::util::function_ref< void(Handle &)> callback)
Walk the list of handles.
static std::shared_ptr< Loop > Create()
Create a new event loop.
Loop & operator=(Loop &&oth)=delete
void Fork()
Reinitialize any kernel state necessary in the child process after a fork(2) system call.
Loop & operator=(const Loop &)=delete
int GetDescriptor() const noexcept
Get backend file descriptor.
Definition Loop.hpp:141
wpi::util::sig::Signal< Error > error
Error signal.
Definition Loop.hpp:248
void Stop() noexcept
Stop the event loop.
Definition Loop.hpp:130
std::shared_ptr< T > GetData() const
Gets user-defined data.
Definition Loop.hpp:229
std::chrono::duration< uint64_t, std::milli > Time
Definition Loop.hpp:38
void ReportError(int err)
Reports error.
Definition Loop.hpp:254
Loop(const Loop &)=delete
uv_loop_t * GetRaw() const noexcept
Get the underlying event loop data structure.
Definition Loop.hpp:222
std::pair< bool, Time > GetTimeout() const noexcept
Get the poll timeout.
Definition Loop.hpp:150
Mode
Definition Loop.hpp:40
@ DEFAULT
Definition Loop.hpp:41
@ ONCE
Definition Loop.hpp:42
@ NO_WAIT
Definition Loop.hpp:43
An efficient, type-erasing, non-owning reference to a callable.
Definition function_ref.hpp:31
Error
Definition def.inc:106
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
UV_EXTERN void uv_stop(uv_loop_t *)
uv_run_mode
Definition uv.h:265
@ UV_RUN_NOWAIT
Definition uv.h:268
@ UV_RUN_ONCE
Definition uv.h:267
@ UV_RUN_DEFAULT
Definition uv.h:266
UV_EXTERN int uv_backend_timeout(const uv_loop_t *)
UV_EXTERN int uv_backend_fd(const uv_loop_t *)
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
UV_EXTERN uint64_t uv_now(const uv_loop_t *)
UV_EXTERN int uv_loop_alive(const uv_loop_t *loop)
UV_EXTERN void uv_update_time(uv_loop_t *)
struct uv_loop_s uv_loop_t
Definition uv.h:215