WPILibC++  2019.3.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
wpi::WorkerThread< R(T...)> Class Template Referencefinal

Public Types

using WorkFunction = std::function< R(T...)>
 
using AfterWorkFunction = typename detail::WorkerThreadAsync< R >::AfterWorkFunction
 

Public Member Functions

void SetLoop (uv::Loop &loop)
 Set the loop. More...
 
void SetLoop (std::shared_ptr< uv::Loop > loop)
 Set the loop. More...
 
void UnsetLoop ()
 Unset the loop. More...
 
std::shared_ptr< uv::HandleGetHandle () const
 Get the handle used by QueueWorkThen() to run afterWork. More...
 
template<typename... U>
future< R > QueueWork (WorkFunction work, U &&...u)
 Wakeup the worker thread, call the work function, and return a future for the result. More...
 
template<typename... U>
void QueueWorkThen (WorkFunction work, AfterWorkFunction afterWork, U &&...u)
 Wakeup the worker thread, call the work function, and call the afterWork function with the result on the loop set by SetLoop(). More...
 

Member Function Documentation

template<typename R , typename... T>
std::shared_ptr<uv::Handle> wpi::WorkerThread< R(T...)>::GetHandle ( ) const
inline

Get the handle used by QueueWorkThen() to run afterWork.

This handle is set by SetLoop(). Calling Close() on this handle is the same as calling UnsetLoop().

Returns
The handle (if nullptr, no handle is set)
template<typename R , typename... T>
template<typename... U>
future<R> wpi::WorkerThread< R(T...)>::QueueWork ( WorkFunction  work,
U &&...  u 
)
inline

Wakeup the worker thread, call the work function, and return a future for the result.

It’s safe to call this function from any thread. The work function will be called on the worker thread.

The future will return a default-constructed result if this class is destroyed while waiting for a result.

Parameters
workWork function (called on worker thread)
template<typename R , typename... T>
template<typename... U>
void wpi::WorkerThread< R(T...)>::QueueWorkThen ( WorkFunction  work,
AfterWorkFunction  afterWork,
U &&...  u 
)
inline

Wakeup the worker thread, call the work function, and call the afterWork function with the result on the loop set by SetLoop().

It’s safe to call this function from any thread. The work function will be called on the worker thread, and the afterWork function will be called on the loop thread.

SetLoop() must be called prior to calling this function for afterWork to be called.

Parameters
workWork function (called on worker thread)
afterWorkAfter work function (called on loop thread)
template<typename R , typename... T>
void wpi::WorkerThread< R(T...)>::SetLoop ( uv::Loop loop)
inline

Set the loop.

This must be called from the loop thread. Subsequent calls to QueueWorkThen will run afterWork on the provided loop (via an async handle).

Parameters
loopthe loop to use for running afterWork routines
template<typename R , typename... T>
void wpi::WorkerThread< R(T...)>::SetLoop ( std::shared_ptr< uv::Loop loop)
inline

Set the loop.

This must be called from the loop thread. Subsequent calls to QueueWorkThen will run afterWork on the provided loop (via an async handle).

Parameters
loopthe loop to use for running afterWork routines
template<typename R , typename... T>
void wpi::WorkerThread< R(T...)>::UnsetLoop ( )
inline

Unset the loop.

This must be called from the loop thread. Subsequent calls to QueueWorkThen will no longer run afterWork.


The documentation for this class was generated from the following file: