7 #include <boost/assert.hpp> 13 _blocked_thread(nullptr),
14 _blocked_fiber_count(0),
18 _cancellation_reason(nullptr),
41 return std::atomic_load( &_exceptp ) !=
nullptr;
45 std::atomic_store( &_exceptp, e );
59 ex->dynamic_rethrow_exception();
78 ptr p_this = shared_from_this();
93 catch (...) { e = std::current_exception(); }
97 if( e ) std::rethrow_exception(e);
99 if( _ready.load() )
return _wait_until( timeout_us );
103 void promise_base::_enqueue_thread(){
104 _blocked_fiber_count.fetch_add( 1 );
105 thread* blocked_thread = _blocked_thread.load();
109 while( !_blocked_thread.compare_exchange_weak( blocked_thread, &
thread::current() ) );
111 void promise_base::_dequeue_thread(){
112 if( _blocked_fiber_count.fetch_add( -1 ) == 1 )
113 _blocked_thread.store(
nullptr );
119 thread* blocked_thread = _blocked_thread.load();
121 blocked_thread->notify( shared_from_this() );
126 if( !_ready.compare_exchange_strong( ready,
true ) )
129 auto* hdl = _compl.load();
131 hdl->on_complete( s, std::atomic_load( &_exceptp ) );
135 auto* hdl = _compl.load();
136 while( !_compl.compare_exchange_weak( hdl, c ) );
void set_exception(const fc::exception_ptr &e)
const char * _cancellation_reason
std::shared_ptr< promise_base > ptr
void _wait(const microseconds &timeout_us)
void _set_value(const void *v)
void _wait_until(const time_point &timeout_us)
virtual void cancel(const char *reason FC_CANCELATION_REASON_DEFAULT_ARG)
promise_base(const char *desc FC_TASK_NAME_DEFAULT_ARG)
std::shared_ptr< exception > exception_ptr
static thread & current()
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
Defines exception's used by fc.
void _on_complete(detail::completion_handler *c)
const char * get_desc() const
static time_point maximum()
static microseconds maximum()