]> Dogcows Code - chaz/yoink/blobdiff - src/moof/runloop.cc
remove some unused stlplus modules
[chaz/yoink] / src / moof / runloop.cc
index 98bc3a22cad4b1b2b46b1258b9fe3d03fb999e5a..f8e4ccfd08596ed6a91e6c1c6109f26854d6ac3a 100644 (file)
@@ -1,15 +1,15 @@
 
-/*]  Copyright (c) 2009-2010, Charles McGarvey  [**************************
+/*]  Copyright (c) 2009-2011, Charles McGarvey  [*****************************
 **]  All rights reserved.
 *
-* vi:ts=4 sw=4 tw=75
-*
 * Distributable under the terms and conditions of the 2-clause BSD license;
 * see the file COPYING for a complete text of the license.
 *
-**************************************************************************/
+*****************************************************************************/
 
+#if HAVE_CONFIG_H
 #include "config.h"
+#endif
 
 #include <algorithm>
 
@@ -27,27 +27,24 @@ bool comp(timer* a, timer* b)
        return a->expiration() < b->expiration();
 }
 
-void runloop::run_once()
+
+int runloop::run_once()
 {
 #if ENABLE_THREADS
        thread_id_ = thread::current_identifier();
 #endif
 
        //log_debug("------------------------------------");
-       //scalar next_event = SCALAR(0.0);
-       {
-               MOOF_MUTEX_LOCK(timers_mutex_);
+       int expired = 0;
+       MOOF_MUTEX_LOCK(timers_mutex_);
 
-               for (timers_it_ = timers_.begin();
-                        timers_it_ != timers_.end();
-                        ++timers_it_)
-               {
-                       (*timers_it_)->fire_if_expired();
-               }
-
-               std::sort(timers_.begin(), timers_.end(), comp);
-               //next_event = timers_[0]->expiration();
+       std::sort(timers_.begin(), timers_.end(), comp);
+       for (timers_it_ = timers_.begin();
+                timers_it_ != timers_.end(); ++timers_it_)
+       {
+               if ((*timers_it_)->fire_if_expired()) ++expired;
        }
+       return expired;
 }
 
 int runloop::run()
@@ -55,22 +52,21 @@ int runloop::run()
        stop_ = false;
        while (!stop_)
        {
-               run_once();
-               //timer::sleep(next_event, timer::absolute);
-               timer::sleep(SCALAR(0.0));
+               if (run_once() == 0);//timer::sleep(SCALAR(0.0));
+               // TODO: maybe sleep(0.0001) will actually return sooner than
+               // sleep(0)... if the kernel interprets sleep(0) as we don't need
+               // to process for an arbitrarily long timespan while specifying a
+               // value lets the kernel know when we need control back...
        }
-
        return code_;
 }
 
-
 void runloop::stop(int code)
 {
        code_ = code;
        stop_ = true;
 }
 
-
 void runloop::add_timer(timer& timer)
 {
 #if ENABLE_THREADS
This page took 0.021617 seconds and 4 git commands to generate.