To be consistent with sys_usleep, set errno and return -1 on error.
| 1008 | |
| 1009 | // To be consistent with sys_usleep, set errno and return -1 on error. |
| 1010 | int TaskGroup::usleep(TaskGroup** pg, uint64_t timeout_us) { |
| 1011 | if (0 == timeout_us) { |
| 1012 | yield(pg); |
| 1013 | return 0; |
| 1014 | } |
| 1015 | TaskGroup* g = *pg; |
| 1016 | // We have to schedule timer after we switched to next bthread otherwise |
| 1017 | // the timer may wake up(jump to) current still-running context. |
| 1018 | SleepArgs e = { timeout_us, g->current_tid(), g->current_task(), g }; |
| 1019 | g->set_remained(_add_sleep_event, &e); |
| 1020 | sched(pg); |
| 1021 | g = *pg; |
| 1022 | if (e.meta->sleep_failed) { |
| 1023 | // Fail to schedule timer, return error. |
| 1024 | e.meta->sleep_failed = false; |
| 1025 | errno = ESTOP; |
| 1026 | return -1; |
| 1027 | } |
| 1028 | e.meta->current_sleep = 0; |
| 1029 | if (e.meta->interrupted) { |
| 1030 | // Race with set and may consume multiple interruptions, which are OK. |
| 1031 | e.meta->interrupted = false; |
| 1032 | // NOTE: setting errno to ESTOP is not necessary from bthread's |
| 1033 | // pespective, however many RPC code expects bthread_usleep to set |
| 1034 | // errno to ESTOP when the thread is stopping, and print FATAL |
| 1035 | // otherwise. To make smooth transitions, ESTOP is still set instead |
| 1036 | // of EINTR when the thread is stopping. |
| 1037 | errno = (e.meta->stop ? ESTOP : EINTR); |
| 1038 | return -1; |
| 1039 | } |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | // Defined in butex.cpp |
| 1044 | bool erase_from_butex_because_of_interruption(ButexWaiter* bw); |
nothing calls this directly
no test coverage detected