Extension API¶
Worker API¶
-
using lf::ext::nullary_function_t = std::function<void()>¶
A type-erased function object that takes no arguments.
-
using lf::ext::submit_handle = impl::submit_node_t*¶
An alias for a pointer to a
submit_t
wrapped in an intruded list.
Lifetime management¶
A worker thread is registered/destroyed by calling the appropriate functions:
-
inline auto lf::ext::worker_init(nullary_function_t notify) -> worker_context*¶
Initialize thread-local variables for a worker.
Returns a handle to the library-managed context for the worker, this context is associated exclusively with the thread that called this function.
Warning
This return value should be cleaned up with
lf::ext::finalize()
.- Parameters:
notify – Called when a task is submitted to a worker, this may be called concurrently.
-
inline void lf::ext::finalize(worker_context *worker)¶
Clean-up thread-local variable before destructing a worker’s context.
This must be called by the same worker (thread) which called
lf::ext::worker_init()
.Warning
These must have been initialized with
worker_init(...)
.
A worker’s context¶
-
class worker_context : private lf::impl::immovable<context>¶
Context for (extension) schedulers to interact with.
Each worker thread stores a context object, this is managed by the library. Internally a context manages the work stealing queue and the submission queue. Submissions to the submission queue trigger a user-supplied notification.
Public Functions
-
inline void schedule(submit_handle jobs)¶
schedule suspended tasks to the context, supports concurrent submission.
This will trigger the notification function.
-
inline auto try_pop_all() noexcept -> submit_handle¶
Fetch a linked-list of the submitted tasks, for use only by the owning worker thread.
If there are no submitted tasks, then returned pointer will be null.
-
inline void schedule(submit_handle jobs)¶
Worker functions¶
-
inline void lf::ext::resume(task_handle ptr)¶
Resume a stolen task.
This thread must be a worker thread.
-
inline void lf::ext::resume(submit_handle ptr)¶
Resume a collection of tasks at a submission point.
This thread must be the worker thread that the tasks were submitted to.