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

Function thread_yield_to

thread/thread.cpp:1316–1341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1314 }
1315
1316 int thread_yield_to(thread* th) {
1317 if (unlikely(th == nullptr)) { // yield to any thread
1318 return thread_yield();
1319 }
1320 RunQ rq;
1321 if (unlikely(th == rq.current)) { // yield to current should just update time
1322 if_update_now();
1323 return 0;
1324 } else if (unlikely(th->vcpu != rq.current->vcpu)) {
1325 LOG_ERROR_RETURN(EINVAL, -1, "target thread ` must be run by the same vcpu as CURRENT!", th);
1326 } else if (unlikely(th->state == states::STANDBY)) {
1327 while (th->state == states::STANDBY)
1328 resume_threads(th->get_vcpu(), rq);
1329 assert(th->state == states::READY);
1330 } else if (unlikely(th->state != states::READY)) {
1331 LOG_ERROR_RETURN(EINVAL, -1, "target thread ` must be READY!", th);
1332 } else if (unlikely(rq.current->next() == th)) {
1333 return thread_yield();
1334 }
1335
1336 auto sw = AtomicRunQ(rq).try_goto(th);
1337 if_update_now();
1338 rq.current->error_number = 0;
1339 switch_context(sw.from, sw.to);
1340 return rq.current->error_number;
1341 }
1342
1343 __attribute__((always_inline)) inline
1344 Switch prepare_usleep(Timeout timeout, thread_list* waitq, RunQ rq = {})

Callers 15

start_loopMethod · 0.85
uds_serverFunction · 0.85
uds_clientFunction · 0.85
tcp_serverFunction · 0.85
tcp_clientFunction · 0.85
et_tcp_serverFunction · 0.85
et_tcp_clientFunction · 0.85
TESTFunction · 0.85
start_loopMethod · 0.85
shutdownMethod · 0.85
TEST_FFunction · 0.85
error_completeFunction · 0.85

Calls 9

thread_yieldFunction · 0.85
if_update_nowFunction · 0.85
resume_threadsFunction · 0.85
AtomicRunQClass · 0.85
switch_contextFunction · 0.85
get_vcpuMethod · 0.80
try_gotoMethod · 0.80
unlikelyFunction · 0.50
nextMethod · 0.45

Tested by 14

uds_serverFunction · 0.68
uds_clientFunction · 0.68
tcp_serverFunction · 0.68
tcp_clientFunction · 0.68
et_tcp_serverFunction · 0.68
et_tcp_clientFunction · 0.68
TESTFunction · 0.68
TEST_FFunction · 0.68
error_completeFunction · 0.68
error_processFunction · 0.68
thread_test_functionFunction · 0.68
TESTFunction · 0.68