BitShares-Core
7.0.2
BitShares blockchain node software and command-line wallet software
|
Go to the documentation of this file.
4 #include <boost/thread.hpp>
6 #include <boost/thread/condition_variable.hpp>
7 #include <boost/thread.hpp>
8 #include <boost/atomic.hpp>
49 static boost::atomic<int> cnt(0);
50 name = std::string(
"th_") + char(
'a'+cnt++);
61 if (ready_context->cur_task)
64 ready_context->cur_task =
nullptr;
129 void debug(
const std::string& s ) {
135 fc::cerr<<
" ---------------------------\n";
140 if( c->cur_task )
fc::cerr<<
'('<<c->cur_task->get_desc()<<
')';
153 if( c->cur_task )
fc::cerr<<
'('<<c->cur_task->get_desc()<<
')';
155 for( uint32_t i = 0; i < c->blocking_prom.size(); ++i ) {
156 fc::cerr<<c->blocking_prom[i].prom<<
'('<<c->blocking_prom[i].prom->get_desc()<<
')';
157 if( i + 1 < c->blocking_prom.size() ) {
170 fc::cerr<<
"-------------------------------------------------\n";
200 return highest_priority_context;
256 unsigned num_ready_tasks = 0;
259 if (cur->
_when <= now)
266 unsigned tasks_posted = 0;
269 if (cur->
_when > now)
332 bool canceled_task =
false;
337 if( (*task_itr)->canceled() )
340 (*task_itr)->release();
342 canceled_task =
true;
351 return canceled_task;
370 ilog(
"throwing canceled exception" );
397 std::stringstream stacktrace;
399 elog(
"Thread ${name} yielded in exception handler!\n${trace}",
432 #if BOOST_VERSION >= 106100
434 auto t = bc::jump_fcontext( next->
my_context, &p );
435 static_cast<context_pair*
>(t.data)->second->my_context = t.fctx;
440 BOOST_ASSERT(
current == prev );
474 #if BOOST_VERSION >= 106100
476 auto t = bc::jump_fcontext( next->
my_context, &p );
477 static_cast<context_pair*
>(t.data)->second->my_context = t.fctx;
482 BOOST_ASSERT(
current == prev );
502 #if BOOST_VERSION >= 106100
506 auto self =
static_cast<thread_d*
>(p->first);
507 p->second->my_context = my.fctx;
517 catch ( canceled_exception& ) { }
526 self->start_next_fiber(
false );
553 for( uint32_t i = 0; i <
free_list.size(); ++i )
639 task_ready.wait_until( lock, boost::chrono::steady_clock::now() +
696 self.async( [
this,c](){
unblock(c); },
"thread_d::unblock" );
711 "Attempting to yield while processing an exception");
747 "Attempting to yield while processing an exception");
786 iter->cleanup(iter->value);
790 iter->cleanup(iter->value);
797 if ((*iter)->canceled)
802 *iter = next_blocked;
808 bool task_removed_from_sleep_pqueue =
false;
811 if ((*sleep_iter)->canceled)
815 if (!already_on_ready_list)
818 task_removed_from_sleep_pqueue =
true;
823 if (task_removed_from_sleep_pqueue)
static thread & current()
uint64_t _posted_num
Task priority looks like unsupported feature.
bool operator()(const context *a, const context *b) const
void remove_blocking_promise(promise_base *p)
fc::context * caller_context
bool start_next_fiber(bool reschedule=false)
uint64_t context_posted_num
bool operator()(task_base *a, task_base *b)
void add_context_to_ready_list(context *context_to_add, bool at_end=false)
boost::thread * boost_thread
std::vector< task_base * > task_sch_queue
unsigned non_preemptable_scope_count
bool process_canceled_tasks()
std::vector< task_base * > task_pqueue
void move_newly_scheduled_tasks_to_task_pqueue()
std::vector< fc::context * > free_list
std::shared_ptr< exception > exception_ptr
const microseconds & time_since_epoch() const
void check_fiber_exceptions()
static void start_process_tasks(intptr_t my)
std::vector< blocked_promise > blocking_prom
thread_d(fc::thread &s, thread_idle_notifier *n=0)
fc::context * next_blocked
bool operator()(const context::ptr &a, const context::ptr &b)
unsigned next_unused_task_storage_slot
boost::atomic< task_base * > task_in_queue
void cleanup_thread_specific_data()
static priority _internal__priority_for_short_sleeps()
void add_to_blocked(fc::context *c)
void enqueue(task_base *t)
void print_stacktrace(std::ostream &out)
std::pair< thread_d *, fc::context * > context_pair
std::vector< fc::context * > sleep_pqueue
bco::protected_stack_allocator stack_allocator
void _set_active_context(context *)
time_point check_for_timeouts()
const char * get_desc() const
void add_blocking_promise(promise_base *p, bool req=true)
void timeout_blocking_promises()
bool operator()(const context *a, const task_base *b) const
bc::fcontext_t my_context
stack_allocator stack_alloc
std::vector< detail::specific_data_info > thread_specific_data
const char * cancellation_reason
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
void yield_until(const time_point &tp, bool reschedule)
boost::condition_variable task_ready
void notify_task_has_been_canceled()
void clear_blocking_promises()
static time_point maximum()
bool operator()(const task_base *a, const task_base *b) const
std::shared_ptr< promise_base > ptr
void unblock(fc::context *c)
std::vector< fc::context * > ready_heap
thread_idle_notifier * notifier
std::vector< detail::specific_data_info > non_task_specific_data
void pt_push_back(fc::context *c)
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
bool operator()(const task_base *a, const context *b) const
void wait(const promise_base::ptr &p, const time_point &timeout)
boost::mutex task_ready_mutex
const string & name() const
returns the name given by set_name() for this thread
fc::context::ptr ready_pop_front()