MCPcopy Create free account
hub / github.com/alibaba/PhotonLibOS / idler

Function idler

thread/thread.cpp:2005–2034  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2003 return false;
2004 }
2005 static void* idler(void*) {
2006 RunQ rq;
2007 auto last_idle = now;
2008 auto vcpu = rq.current->get_vcpu();
2009 while (vcpu->state != states::DONE) {
2010 while (unlikely(resume_threads_inlined(vcpu, rq) > 0) ||
2011 likely(!AtomicRunQ(rq).single()) ||
2012 likely(try_work_stealing(vcpu))) {
2013 thread_yield();
2014 if (vcpu->state == states::DONE)
2015 break;
2016 if (unlikely(sat_sub(now, last_idle) >= 1000UL)) {
2017 vcpu->master_event_engine->wait_and_fire_events(0);
2018 last_idle = now;
2019 }
2020 }
2021 if (vcpu->state == states::DONE)
2022 break;
2023 // only idle stub aliving
2024 // other threads must be sleeping
2025 // fall in actual sleep
2026 auto usec = 10 * 1024 * 1024; // max
2027 auto& sleepq = vcpu->sleepq;
2028 if (!sleepq.empty()) usec = min(usec,
2029 sat_sub(sleepq.front()->ts_wakeup, now));
2030 vcpu->master_event_engine->wait_and_fire_events(usec);
2031 last_idle = now;
2032 }
2033 return nullptr;
2034 }
2035 /**
2036 * Waiting for all current vcpu photon threads finish
2037 * @return 0 for all done, -1 for failure

Callers

nothing calls this directly

Calls 13

resume_threads_inlinedFunction · 0.85
AtomicRunQClass · 0.85
try_work_stealingFunction · 0.85
thread_yieldFunction · 0.85
minFunction · 0.85
get_vcpuMethod · 0.80
unlikelyFunction · 0.50
likelyFunction · 0.50
sat_subFunction · 0.50
singleMethod · 0.45
wait_and_fire_eventsMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected