mp-coro main
Coroutine support tools
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Related Functions | List of all members
synchronized_task< Sync, T > Class Template Reference

#include <mp-coro/bits/synchronized_task.h>

Detailed Description

template<sync_notification_type Sync, task_value_type T>
class mp_coro::detail::synchronized_task< Sync, T >

Lazy task that can later be started explicitly, and that notifies another variable (the “sync” object) of its completion.

This class doesn't spawn any threads itself, it just defines a coroutine with the notification of the “sync” object as its continuation.

Definition at line 39 of file synchronized_task.h.

+ Collaboration diagram for synchronized_task< Sync, T >:

Classes

struct  promise_type
 Required promise type for coroutines returning a synchronized_task. More...
 

Public Types

using value_type = T
 The type of the value produced by this synchronized_task. More...
 

Public Member Functions

 synchronized_task (synchronized_task &&)=default
 Move constructor. More...
 
synchronized_taskoperator= (synchronized_task &&)=delete
 Move assignment not allowed. More...
 
void start (Sync &s)
 Start (resume) execution of the synchronized_task. More...
 
decltype(auto) get () const &
 Get the value produced by this task. More...
 
decltype(auto) get () const &&
 Get the value produced by this task. More...
 
decltype(auto) nonvoid_get () const &
 Get the value produced by this task. More...
 
decltype(auto) nonvoid_get () const &&
 Get the value produced by this task. More...
 

Private Member Functions

 synchronized_task (promise_type *promise)
 Private constructor used in promise_type::get_return_object. More...
 

Private Attributes

promise_ptr< promise_typepromise_
 An owning pointer to the promise object in the coroutine frame. More...
 

Related Functions

(Note that these are not member functions.)

template<sync_notification_type Sync, awaitable A>
synchronized_task< Sync, remove_rvalue_reference_t< await_result_t< A > > > make_synchronized_task (A &&awaitable)
 Coroutine returning an synchronized_task that awaits the given awaitable and returns its result. More...
 

Member Typedef Documentation

◆ value_type

using value_type = T

The type of the value produced by this synchronized_task.

Definition at line 42 of file synchronized_task.h.

Constructor & Destructor Documentation

◆ synchronized_task() [1/2]

synchronized_task ( synchronized_task< Sync, T > &&  )
default

Move constructor.

◆ synchronized_task() [2/2]

synchronized_task ( promise_type promise)
inlineprivate

Private constructor used in promise_type::get_return_object.

Definition at line 126 of file synchronized_task.h.

Member Function Documentation

◆ operator=()

synchronized_task & operator= ( synchronized_task< Sync, T > &&  )
delete

Move assignment not allowed.

◆ start()

void start ( Sync &  s)
inline

Start (resume) execution of the synchronized_task.

Parameters
sReference to the “sync” object, i.e. the variable to notify of the task's completion. When the task is suspended at its final suspension point, s.notify_awaitable_completed() is called.
Note
s.notify_awaitable_completed() is called directly in promise_type::final_awaiter::await_suspend(), it does not (and cannot) use Symmetric Control Transfer.

Definition at line 91 of file synchronized_task.h.

◆ get() [1/2]

decltype(auto) get ( ) const &
inline

Get the value produced by this task.

Must be called after the “sync” object passed to start() has been notified.

Definition at line 99 of file synchronized_task.h.

◆ get() [2/2]

decltype(auto) get ( ) const &&
inline

Get the value produced by this task.

Must be called after the “sync” object passed to start() has been notified.

Definition at line 104 of file synchronized_task.h.

◆ nonvoid_get() [1/2]

decltype(auto) nonvoid_get ( ) const &
inline

Get the value produced by this task.

Must be called after the “sync” object passed to start() has been notified.

Definition at line 109 of file synchronized_task.h.

◆ nonvoid_get() [2/2]

decltype(auto) nonvoid_get ( ) const &&
inline

Get the value produced by this task.

Must be called after the “sync” object passed to start() has been notified.

Definition at line 114 of file synchronized_task.h.

Friends And Related Function Documentation

◆ make_synchronized_task()

synchronized_task< Sync, remove_rvalue_reference_t< await_result_t< A > > > make_synchronized_task ( A &&  awaitable)
related

Coroutine returning an synchronized_task that awaits the given awaitable and returns its result.

Definition at line 135 of file synchronized_task.h.

Member Data Documentation

◆ promise_

promise_ptr<promise_type> promise_
private

An owning pointer to the promise object in the coroutine frame.

When the task is destructed, this will cause the coroutine frame to be destroyed automatically.

Definition at line 123 of file synchronized_task.h.


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