Lely core libraries
2.3.4
|
Go to the documentation of this file.
26 #if !LELY_NO_COAPP_MASTER && !LELY_NO_THREADS
58 ::std::atomic_flag shutdown{
false};
65 ::std::atomic_flag joined{
false};
78 :
BasicDriver(strand.get_inner_executor(), master, id),
79 impl_(new
Impl_(this, master.GetContext())) {}
90 return impl_->stopped.get_future();
98 }
catch (const ::std::system_error& e) {
107 ::std::error_code ec;
109 if (ec) throw ::std::system_error(ec,
"USleep");
127 thread(&Impl_::Start, this)
133 [](
void* arg) noexcept {
138 util::throw_errc(
"thrd_create");
143 LoopDriver::Impl_::~Impl_() {
149 LoopDriver::Impl_::Start() {
150 auto& loop =
self->GetLoop();
151 auto exec =
self->GetExecutor();
161 self->master.Erase(*
self);
173 LoopDriver::Impl_::Shutdown() {
174 if (!shutdown.test_and_set()) {
176 self->master.Erase(*
self);
178 self->GetLoop().stop();
183 LoopDriver::Impl_::Join() {
184 if (!joined.test_and_set()) {
198 #endif // !LELY_NO_COAPP_MASTER && !LELY_NO_THREADS
BasicMaster & master
A reference to the master with which this driver is registered.
ev::Future< void, ::std::exception_ptr > AsyncWait(ev_exec_t *exec, const time_point &t, io_tqueue_wait **pwait=nullptr)
Submits an asynchronous wait operation and creates a future which becomes ready once the wait operati...
The base class for drivers for remote CANopen nodes.
ev::Future< void, void > AsyncStoppped() noexcept
Returns a future which becomes ready once the dedicated event loop of the driver is stopped and the t...
pthread_t thrd_t
A complete object type that holds an identifier for a thread.
The virtual table of an I/O service.
#define IO_SVC_INIT(vptr)
The static initializer for io_svc.
An asynchronous CANopen master.
A refence to an I/O context. This class is a wrapper around #io_ctx_t*.
A CANopen driver running its own dedicated event loop in a separate thread.
void remove(io_svc &svc) noexcept
@ thrd_success
Indicates that the requested operation succeeded.
T Wait(SdoFuture< T > f)
Waits for the specified future to become ready by running pending tasks on the dedicated event loop o...
A wait operation suitable for use with a timer queue.
The internal implementation of lely::canopen::LoopDriver.
bool CancelWait(io_tqueue_wait &wait) noexcept
Cancels the specified wait operation if it is pending.
int thrd_join(thrd_t thr, int *res)
Joins the thread identified by thr with the current thread by blocking until the other thread has ter...
int thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
Creates a new thread executing func(arg).
The exception thrown when retrieving the result of a future which is not ready or does not contain a ...
void USleep(uint_least64_t usec)
Runs the event loop for usec microseconds.
::std::size_t wait(ev_future_t *future)
ev::Loop & GetLoop() noexcept
Returns a reference to the dedicated event loop of the driver.
::std::error_code make_error_code(SdoErrc e) noexcept
Creates an error code corresponding to an SDO abort code.
~LoopDriver()
Stops the event loop and terminates the thread in which it was running before destroying the driver.
void Join()
Stops the dedicated event loop of the driver and waits until the thread running the event loop finish...