Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 KB | None | 0 0
  1. void Scheduler::RunLoop() {
  2.   while (!run_queue_.IsEmpty() || !sleep_queue_.IsEmpty()) {
  3.     Fiber* next = nullptr;
  4.     while (!sleep_queue_.IsEmpty() && (next = sleep_queue_.TryPop())) {
  5.       next->SetState(FiberState::Runnable);
  6.       run_queue_.PushBack(next);
  7.     }
  8.  
  9.     if (!run_queue_.IsEmpty()) {
  10.       next = run_queue_.PopFront();
  11.       SwitchTo(next);
  12.       Reschedule(next);
  13.     } else if (!sleep_queue_.IsEmpty()){
  14.       sleep_queue_.Sleep();
  15.     }
  16.   }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement