MCPcopy Create free account
hub / github.com/a2flo/floor / _thread_run

Method _thread_run

threading/thread_base.cpp:65–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65int thread_base::_thread_run(thread_base* this_thread_obj) {
66 this_thread_obj->lock();
67 core::set_current_thread_name(this_thread_obj->thread_name);
68 this_thread_obj->unlock();
69
70 while(true) {
71 // wait until we get the thread lock
72 if(this_thread_obj->try_lock()) {
73 // if the "finish flag" has been set in the mean time, don't call the run method!
74 if(!this_thread_obj->thread_should_finish()) {
75 try {
76 this_thread_obj->run();
77 } catch(exception& exc) {
78 log_error("encountered an unhandled exception while running a thread \"$\": $",
79 core::get_current_thread_name(), exc.what());
80 } catch(...) {
81 log_error("encountered an unhandled exception while running a thread \"$\"",
82 core::get_current_thread_name());
83 }
84 }
85 this_thread_obj->unlock();
86
87 // again: if the "finish flag" has been set, don't wait, but continue immediately
88 if(!this_thread_obj->thread_should_finish()) {
89 // reduce system load and make other locks possible
90 const size_t thread_delay = this_thread_obj->get_thread_delay();
91 if(thread_delay > 0) {
92 this_thread::sleep_for(chrono::milliseconds(thread_delay));
93 }
94 else {
95 if(this_thread_obj->get_yield_after_run()) {
96 // just yield when delay == 0 and "yield after run" flag is set
97 this_thread::yield();
98 }
99 }
100 }
101 }
102 else {
103 if(this_thread_obj->get_yield_after_run()) {
104 this_thread::yield();
105 }
106 }
107
108 if(this_thread_obj->thread_should_finish()) {
109 break;
110 }
111 }
112 this_thread_obj->set_thread_status(THREAD_STATUS::FINISHED);
113
114 return 0;
115}
116
117void thread_base::finish() {
118 if (thread_obj != nullptr) {

Callers

nothing calls this directly

Calls 10

get_current_thread_nameFunction · 0.85
lockMethod · 0.80
unlockMethod · 0.80
try_lockMethod · 0.80
thread_should_finishMethod · 0.80
whatMethod · 0.80
get_thread_delayMethod · 0.80
get_yield_after_runMethod · 0.80
set_thread_statusMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected