Lely core libraries
2.2.5
|
Go to the documentation of this file.
24 #ifndef LELY_EV_LOOP_HPP_
25 #define LELY_EV_LOOP_HPP_
34 #include <type_traits>
49 bool poll_task =
false)
51 if (!loop_) util::throw_errc(
"Loop");
56 Loop(
Loop&& other) noexcept : loop_(other.loop_) { other.loop_ =
nullptr; }
58 Loop& operator=(
const Loop&) =
delete;
61 operator=(
Loop&& other) noexcept {
63 swap(loop_, other.loop_);
70 operator ev_loop_t*()
const noexcept {
return loop_; }
105 ::std::error_code ec;
106 auto result =
wait(future, ec);
107 if (ec) throw ::std::system_error(ec,
"wait");
123 template <
class Rep,
class Period>
126 return wait_until(future, ::std::chrono::system_clock::now() + d);
130 template <
class Rep,
class Period>
133 ::std::error_code& ec) noexcept {
134 return wait_until(future, ::std::chrono::system_clock::now() + d, ec);
138 template <
class Clock,
class Duration>
141 const ::std::chrono::time_point<Clock, Duration>& t) {
143 util::to_timespec(compat::clock_cast<::std::chrono::system_clock>(t));
148 template <
class Clock,
class Duration>
151 const ::std::chrono::time_point<Clock, Duration>& t,
152 ::std::error_code& ec) noexcept {
154 util::to_timespec(compat::clock_cast<::std::chrono::system_clock>(t));
161 ::std::error_code ec;
163 if (ec) throw ::std::system_error(ec,
"wait_one");
179 template <
class Rep,
class Period>
182 const ::std::chrono::duration<Rep, Period>& d) {
183 return wait_one_until(future, ::std::chrono::system_clock::now() + d);
187 template <
class Rep,
class Period>
190 const ::std::chrono::duration<Rep, Period>& d,
191 ::std::error_code& ec) noexcept {
192 return wait_one_until(future, ::std::chrono::system_clock::now() + d, ec);
196 template <
class Clock,
class Duration>
199 const ::std::chrono::time_point<Clock, Duration>& t) {
201 util::to_timespec(compat::clock_cast<::std::chrono::system_clock>(t));
206 template <
class Clock,
class Duration>
209 const ::std::chrono::time_point<Clock, Duration>& t,
210 ::std::error_code& ec) noexcept {
212 util::to_timespec(compat::clock_cast<::std::chrono::system_clock>(t));
219 ::std::error_code ec;
220 auto result =
run(ec);
221 if (ec) throw ::std::system_error(ec,
"run");
227 run(::std::error_code& ec) noexcept {
237 template <
class Rep,
class Period>
239 run_for(const ::std::chrono::duration<Rep, Period>& d) {
240 return run_until(::std::chrono::system_clock::now() + d);
244 template <
class Rep,
class Period>
246 run_for(const ::std::chrono::duration<Rep, Period>& d,
247 ::std::error_code& ec) noexcept {
248 return run_until(::std::chrono::system_clock::now() + d, ec);
252 template <
class Clock,
class Duration>
254 run_until(const ::std::chrono::time_point<Clock, Duration>& t) {
256 util::to_timespec(compat::clock_cast<::std::chrono::system_clock>(t));
261 template <
class Clock,
class Duration>
263 run_until(const ::std::chrono::time_point<Clock, Duration>& t,
264 ::std::error_code& ec) noexcept {
266 util::to_timespec(compat::clock_cast<::std::chrono::system_clock>(t));
273 ::std::error_code ec;
275 if (ec) throw ::std::system_error(ec,
"run_one");
291 template <
class Rep,
class Period>
294 return run_one_until(::std::chrono::system_clock::now() + d);
298 template <
class Rep,
class Period>
301 ::std::error_code& ec) noexcept {
302 return run_one_until(::std::chrono::system_clock::now() + d, ec);
306 template <
class Clock,
class Duration>
310 util::to_timespec(compat::clock_cast<::std::chrono::system_clock>(t));
315 template <
class Clock,
class Duration>
318 ::std::error_code& ec) noexcept {
320 util::to_timespec(compat::clock_cast<::std::chrono::system_clock>(t));
327 ::std::error_code ec;
328 auto result =
poll(ec);
329 if (ec) throw ::std::system_error(ec,
"poll");
335 poll(::std::error_code& ec) noexcept {
347 ::std::error_code ec;
349 if (ec) throw ::std::system_error(ec,
"poll_one");
373 if (
ev_loop_kill(*
this, thr) == -1) util::throw_errc(
"kill");
379 ::std::error_code ec;
380 auto result =
wait_until(future, abs_time, ec);
382 throw ::std::system_error(ec,
"wait_until");
388 ::std::error_code& ec) noexcept {
399 ::std::error_code ec;
402 throw ::std::system_error(ec,
"wait_one_until");
408 ::std::error_code& ec) noexcept {
419 ::std::error_code ec;
422 throw ::std::system_error(ec,
"run_until");
427 run_until(
const timespec* abs_time, ::std::error_code& ec) noexcept {
438 ::std::error_code ec;
441 throw ::std::system_error(ec,
"run_one_until");
446 run_one_until(
const timespec* abs_time, ::std::error_code& ec) noexcept {
462 #endif // !LELY_EV_LOOP_HPP_
::std::size_t run_one_for(const ::std::chrono::duration< Rep, Period > &d)
size_t ev_loop_run_one(ev_loop_t *loop)
Equivalent to ev_loop_wait_one(loop, NULL).
::std::size_t wait_one(ev_future_t *future)
ev_poll_t * ev_loop_get_poll(const ev_loop_t *loop)
Returns a pointer to the polling instance used by the event loop, or NULL if the loop does not poll.
::std::size_t wait_until(ev_future_t *future, const ::std::chrono::time_point< Clock, Duration > &t, ::std::error_code &ec) noexcept
::std::size_t wait_for(ev_future_t *future, const ::std::chrono::duration< Rep, Period > &d)
ev_loop_t * ev_loop_create(ev_poll_t *poll, size_t npoll, int poll_task)
Creates a new polling event loop.
::std::size_t run_one_until(const ::std::chrono::time_point< Clock, Duration > &t)
void ev_loop_restart(ev_loop_t *loop)
Restarts an event loop.
const struct ev_poll_vtbl *const ev_poll_t
The abstract polling interface.
size_t ev_loop_poll(ev_loop_t *loop)
Equivalent to ev_loop_run_until(loop, NULL).
::std::size_t run_for(const ::std::chrono::duration< Rep, Period > &d)
::std::size_t wait_for(ev_future_t *future, const ::std::chrono::duration< Rep, Period > &d, ::std::error_code &ec) noexcept
Executor get_executor() const noexcept
::std::size_t wait_one_for(ev_future_t *future, const ::std::chrono::duration< Rep, Period > &d)
size_t ev_loop_run(ev_loop_t *loop)
Equivalent to ev_loop_wait(loop, NULL).
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
::std::size_t run_for(const ::std::chrono::duration< Rep, Period > &d, ::std::error_code &ec) noexcept
::std::size_t run(::std::error_code &ec) noexcept
size_t ev_loop_wait_one_until(ev_loop_t *loop, ev_future_t *future, const struct timespec *abs_time)
If the event loop has pending tasks, runs a single task.
::std::size_t wait_one(ev_future_t *future, ::std::error_code &ec) noexcept
size_t ev_loop_run_until(ev_loop_t *loop, const struct timespec *abs_time)
Equivalent to ev_loop_wait_until(loop, NULL, abs_time).
int ev_loop_stopped(const ev_loop_t *loop)
Returns 1 if the event loop is stopped, and 0 if not.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
An abstract task executor. This class is a wrapper around #ev_exec_t*.
bool stopped() const noexcept
@ see ev_loop_stopped()
::std::size_t run_until(const ::std::chrono::time_point< Clock, Duration > &t, ::std::error_code &ec) noexcept
int ev_loop_kill(ev_loop_t *loop, void *thr)
Interrupts an event loop running on the specified thread.
::std::size_t poll(::std::error_code &ec) noexcept
size_t ev_loop_poll_one(ev_loop_t *loop)
Equivalent to ev_loop_run_one_until(loop, NULL).
Poll get_poll() const noexcept
ev_exec_t * ev_loop_get_exec(const ev_loop_t *loop)
Returns a pointer to the executor corresponding to the event loop.
size_t ev_loop_wait(ev_loop_t *loop, ev_future_t *future)
Equivalent to.
void ev_loop_stop(ev_loop_t *loop)
Stops the event loop.
errnum_t errc2num(int errc)
Transforms a native error code to a platform-independent error number.
::std::size_t wait_until(ev_future_t *future, const ::std::chrono::time_point< Clock, Duration > &t)
Loop(ev_poll_t *poll=nullptr, ::std::size_t npoll=1, bool poll_task=false)
The abstract polling interface.
::std::size_t wait(ev_future_t *future)
::std::size_t wait_one_for(ev_future_t *future, const ::std::chrono::duration< Rep, Period > &d, ::std::error_code &ec) noexcept
::std::size_t run_one_for(const ::std::chrono::duration< Rep, Period > &d, ::std::error_code &ec) noexcept
::std::size_t wait_one_until(ev_future_t *future, const ::std::chrono::time_point< Clock, Duration > &t, ::std::error_code &ec) noexcept
::std::size_t wait_one_until(ev_future_t *future, const ::std::chrono::time_point< Clock, Duration > &t)
@ ERRNUM_TIMEDOUT
Connection timed out.
void ev_loop_destroy(ev_loop_t *loop)
Destroys a polling event loop.
void * ev_loop_self(void)
Returns the identifier of the calling thread.
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
::std::size_t run_one_until(const ::std::chrono::time_point< Clock, Duration > &t, ::std::error_code &ec) noexcept
::std::size_t wait(ev_future_t *future, ::std::error_code &ec) noexcept
::std::size_t run_one(::std::error_code &ec) noexcept
::std::size_t run_until(const ::std::chrono::time_point< Clock, Duration > &t)
::std::size_t poll_one(::std::error_code &ec) noexcept
size_t ev_loop_wait_until(ev_loop_t *loop, ev_future_t *future, const struct timespec *abs_time)
Equivalent to.
size_t ev_loop_wait_one(ev_loop_t *loop, ev_future_t *future)
If the event loop has pending tasks, runs a single task.
size_t ev_loop_run_one_until(ev_loop_t *loop, const struct timespec *abs_time)
Equivalent to ev_loop_wait_one_until(loop, NULL, abs_time).