SHARE
TWEET

Untitled

a guest Jun 10th, 2019 134 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     void MainLoop() {
  2.         while(true) {
  3.             Mutex&      mutex = condvar_.mutex();
  4.             CondVar&    cv = condvar_.condvar();
  5.             Message*    msg;
  6.  
  7.             // Process all enqueued messages,
  8.             // waiting for next msg if the queue is empty.
  9.             {
  10.                 // Lock the queue
  11.                 MutexLock lock(mutex);
  12.                 // Get a message if there is one
  13.                 msg = queue_.Pop();
  14.                 // If there was no msg in the queue
  15.                 // wait till we get one.
  16.                 // condvar may get a spurious wake,
  17.                 // thus we should wait again if the queue is still empty.
  18.                 while(!msg) {
  19.                     cv.Wait();
  20.                     msg = queue_.Pop();
  21.                 }
  22.                 // Unlock the queue when MutexLock goes out of scope
  23.             }
  24.  
  25.             // Handle the message (a slow activity)
  26.             ProcessMessage(msg);
  27.         }
  28.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top