21 #include <quantum/quantum_allocator.h> 29 template <
template<
class>
class PROMISE,
class T>
30 template <
class V,
class>
33 return static_cast<Impl*>(
this)->set(std::forward<V>(value));
36 template <
template<
class>
class PROMISE,
class T>
37 template <
class V,
class>
40 static_cast<Impl*>(
this)->push(std::forward<V>(value));
43 template <
template<
class>
class PROMISE,
class T>
44 template <
class V,
class>
47 return static_cast<Impl*>(
this)->closeBuffer();
53 template <
template<
class>
class PROMISE,
class T>
54 template <
class V,
class>
57 return static_cast<Impl*>(
this)->set(sync, std::forward<V>(value));
60 template <
template<
class>
class PROMISE,
class T>
61 template <
class V,
class>
64 static_cast<Impl*>(
this)->push(sync, std::forward<V>(value));
67 template <
template<
class>
class PROMISE,
class T>
68 template <
class V,
class>
71 return static_cast<Impl*>(
this)->closeBuffer();
77 #ifndef __QUANTUM_PROMISE_ALLOC_SIZE 78 #define __QUANTUM_PROMISE_ALLOC_SIZE __QUANTUM_DEFAULT_POOL_ALLOC_SIZE 80 #ifndef __QUANTUM_USE_DEFAULT_ALLOCATOR 81 #ifdef __QUANTUM_ALLOCATE_POOL_FROM_HEAP 95 _terminated ATOMIC_FLAG_INIT
107 if (!_terminated.test_and_set())
109 if (_sharedState) _sharedState->breakPromise();
116 return _sharedState !=
nullptr;
123 return _sharedState->setException(ex);
141 template <
class V,
class>
145 return _sharedState->set(std::forward<V>(value));
156 template <
class V,
class>
160 return _sharedState->set(sync, std::forward<V>(value));
171 template <
class V,
class>
175 _sharedState->push(std::forward<V>(value));
179 template <
class V,
class>
183 _sharedState->push(sync, std::forward<V>(value));
187 template <
class V,
class>
191 return _sharedState->closeBuffer();
209 #ifndef __QUANTUM_USE_DEFAULT_ALLOCATOR static AllocType & instance(std::enable_if_t<!A::default_constructor::value, uint16_t > size)
Definition: quantum_allocator.h:56
Definition: quantum_buffer_impl.h:22
typename ICoroFuture< T >::Ptr CoroFuturePtr
Definition: quantum_icoro_future.h:72
Shared state used between a Promise and a Future to exchange values.
Definition: quantum_shared_state.h:38
Definition: quantum_allocator.h:36
void push(V &&value)
Definition: quantum_promise_impl.h:172
int set(ICoroSync::Ptr sync, V &&value)
Set the promised value.
Definition: quantum_promise_impl.h:55
ThreadFuturePtr< T > getIThreadFuture() const
Get the associated thread future.
Definition: quantum_promise_impl.h:149
int closeBuffer()
Close a promise buffer.
Definition: quantum_promise_impl.h:45
int setException(std::exception_ptr ex) final
Set an exception in this promise.
Definition: quantum_promise_impl.h:120
bool valid() const final
Determines if this promise still has a shared state with the corresponding future object.
Definition: quantum_promise_impl.h:114
int set(V &&value)
Definition: quantum_promise_impl.h:142
void push(V &&value)
Push a single value into the promise buffer.
Definition: quantum_promise_impl.h:38
std::shared_ptr< ICoroSync > Ptr
Definition: quantum_icoro_sync.h:36
static void deleter(Promise< T > *p)
Definition: quantum_promise_impl.h:207
Class representing a promised value.
Definition: quantum_icoro_promise.h:77
ICoroFutureBase::Ptr getICoroFutureBase() const final
Get a coroutine-compatible interface used to access the associated future.
Definition: quantum_promise_impl.h:134
Exposes methods to access and manipulate a non-coroutine promise (i.e. used in a thread)
Definition: quantum_ithread_promise.h:34
Provides a stack-based object pool to the underlying ContiguousPoolManager. The default buffer size i...
Definition: quantum_stack_allocator.h:34
Class representing a promised future. Can only be instantiated via a Promise object.
Definition: quantum_icoro_future.h:27
typename Future< T >::Ptr FuturePtr
Definition: quantum_future.h:91
Promise()
Definition: quantum_promise_impl.h:91
static size_type & promiseAllocSize()
Get/set if the default size for promise object pools.
Definition: quantum_allocator_traits.h:114
std::shared_ptr< ICoroFutureBase > Ptr
Definition: quantum_icoro_future_base.h:34
void ThrowFutureException(FutureState state)
Definition: quantum_future_state.h:130
std::shared_ptr< IThreadFutureBase > Ptr
Definition: quantum_ithread_future_base.h:34
void terminate() final
Terminates the object.
Definition: quantum_promise_impl.h:105
Provides a heap-based object pool to the underlying ContiguousPoolManager. The default buffer size is...
Definition: quantum_heap_allocator.h:33
typename IThreadFuture< T >::Ptr ThreadFuturePtr
Definition: quantum_ithread_future.h:69
Exposes methods to access and manipulate a coroutine-compatible promise.
Definition: quantum_icoro_promise.h:33
int closeBuffer()
Close a promise buffer.
Definition: quantum_promise_impl.h:69
int set(V &&value)
Set the promised value.
Definition: quantum_promise_impl.h:31
int closeBuffer()
Definition: quantum_promise_impl.h:188
void push(ICoroSync::Ptr sync, V &&value)
Push a single value into the promise buffer.
Definition: quantum_promise_impl.h:62
Shared state between Promise and Future is invalid.
IThreadFutureBase::Ptr getIThreadFutureBase() const final
Get a thread-compatible interface used to access the associated future.
Definition: quantum_promise_impl.h:127
CoroFuturePtr< T > getICoroFuture() const
Get the associated coroutine future.
Definition: quantum_promise_impl.h:164