template class EE::detail::TaskSharedState

Overview

State shared by one Task<T> and the copies of its TaskResolver<T>. More…

#include <task.hpp>

template <typename T>
class TaskSharedState {
public:
    // typedefs

    typedef std::conditional_t<std::is_void_v<T>, TaskVoidValue, T> Value;
    typedef SmallUniqueFunction<void(TaskSharedState&), 64> Continuation;

    // methods

    void retain();
    void release();
    void retainResolver();
    bool releaseResolver();
    TaskState state() const;

    template <typename... Args>
    bool resolve(Args&&... args);

    bool abandon();
    void attach(Continuation continuation);
    TaskState wait();

    template <typename Rep, typename Period>
    TaskState waitFor(const std::chrono::duration<Rep, Period>& timeout);

    Value& value();
};

Detailed Documentation

State shared by one Task<T> and the copies of its TaskResolver<T>.

Reference counting is intrusive so that continuations can re-acquire ownership from the plain reference they receive (needed to keep the value alive while a continuation is queued on an executor) and so that every task costs exactly one allocation. Resolver copies are counted apart, so the task is abandoned when the last resolver goes away, whoever else still holds the state.

Methods

bool releaseResolver()

Returns:

True if the last resolver was released.

bool abandon()

Returns:

True if this call moved the state from Pending to Abandoned.

void attach(Continuation continuation)

Stores the continuation, or runs it immediately if the state is already terminal. Never invokes user code while holding the mutex.

Value& value()

Only valid once Ready, and only from the single consumer.