8 #if defined(_MSC_VER) && !defined(NDEBUG)
10 const DWORD MS_VC_EXCEPTION=0x406D1388;
13 typedef struct tagTHREADNAME_INFO
22 static void set_thread_name(
const char* threadName)
26 info.szName = threadName;
32 RaiseException(MS_VC_EXCEPTION, 0,
sizeof(info)/
sizeof(ULONG_PTR), (ULONG_PTR*)&info);
34 __except(EXCEPTION_EXECUTE_HANDLER)
38 #elif defined(__linux__)
40 static void set_thread_name(
const char* threadName)
42 pthread_setname_np(pthread_self(), threadName);
44 #elif defined(__APPLE__) && !defined(NDEBUG)
46 static void set_thread_name(
const char* threadName)
48 pthread_setname_np(threadName);
51 static void set_thread_name(
const char* threadName)
69 static __thread
thread* t = NULL;
76 boost::thread* t =
new boost::thread( [
this,p,
name,notifier]() {
78 set_thread_name(
name.c_str());
79 this->my =
new thread_d( *
this, notifier );
87 wlog(
"unhandled exception" );
92 std::cerr <<
"unhandled exception in thread '" <<
name <<
"'\n";
98 wlog(
"unhandled exception" );
99 p->
set_exception( std::make_shared<unhandled_exception>(
FC_LOG_MESSAGE( warn,
"unhandled exception: ${diagnostic}", (
"diagnostic",boost::current_exception_diagnostic_information()) ) ) );
103 std::cerr <<
"unhandled exception in thread '" <<
name <<
"'\n";
104 std::cerr << boost::current_exception_diagnostic_information() <<
"\n";
151 set_thread_name(my->
name.c_str());
163 #if defined(__linux__) || defined(__APPLE__)
169 #if defined(__linux__) || defined(__APPLE__)
181 async( [
this](){
quit();},
"thread::quit" );
205 BOOST_ASSERT( my->
blocked == 0 );
208 unstarted_task->
set_exception(std::make_shared<canceled_exception>(
FC_LOG_MESSAGE(error,
"cancellation reason: thread quitting")));
212 scheduled_task->
set_exception(std::make_shared<canceled_exception>(
FC_LOG_MESSAGE(error,
"cancellation reason: thread quitting")));
256 catch( canceled_exception& e )
258 dlog(
"thread canceled: ${e}", (
"e", e.to_detail_string()) );
292 for(
size_t i = 0; i < p.size(); ++i )
299 for(
auto i = p.begin(); i != p.end(); ++i )
300 ss << (*i)->get_desc() <<
", ";
308 for( uint32_t i = 0; i < p.size(); ++i )
318 sleep_priority_less() );
324 for(
auto i = p.begin(); i != p.end(); ++i )
329 for( uint32_t i = 0; i < p.size(); ++i )
336 void thread::async_task( task_base* t,
const priority& p ) {
353 do { t->
_next = stale_head;
354 }
while( !my->
task_in_queue.compare_exchange_weak( stale_head, t, boost::memory_order_release ) );
359 if(
this != &
current() && !stale_head ) {
410 sleep_priority_less() );
424 BOOST_ASSERT(p->ready());
457 auto cur = cur_blocked;
473 prev_blocked = cur_blocked;
484 void thread::notify_task_has_been_canceled()
504 work->
_next = stale_head;
505 }
while( !t->
task_in_queue.compare_exchange_weak( stale_head, work, boost::memory_order_release ) );
511 if( notifier ) notifier->
busy();
519 unhandled_exception_filter_type unhandled_structured_exception_filter =
nullptr;
521 void set_unhandled_structured_exception_filter(unhandled_exception_filter_type new_filter)
523 detail::unhandled_structured_exception_filter = new_filter;
525 unhandled_exception_filter_type get_unhandled_structured_exception_filter()
527 return detail::unhandled_structured_exception_filter;