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 ) );