X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Frunloop.hh;h=43d4ea2e580fc2e2f5982797401a3a1e6caae20a;hp=0aad06dddaa9a25c82fc2f9d1e17c2c4af3d5667;hb=44b3014bce798789e795242d1556cb7449e6386a;hpb=d6990468d297a6cbee98e4d0d33ab37e1b2352c9 diff --git a/src/moof/runloop.hh b/src/moof/runloop.hh index 0aad06d..43d4ea2 100644 --- a/src/moof/runloop.hh +++ b/src/moof/runloop.hh @@ -1,41 +1,37 @@ -/*] 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. * -**************************************************************************/ +*****************************************************************************/ #ifndef _MOOF_RUNLOOP_HH_ #define _MOOF_RUNLOOP_HH_ -/** - * \file runloop.hh - * Thread timer management class. - */ - -#include +#include #include -#include #include +/** + * \file runloop.hh + * Thread timer management class. + */ + namespace moof { // forward declarations class timer; - /** * A runloop is a loop with scheduled timers. */ -class runloop +class runloop : public boost::noncopyable { public: @@ -43,14 +39,18 @@ public: * Construct a runloop. */ runloop() : - stop_(false), - thread_id_(0) {} + stop_(false) + { +#if ENABLE_THREADS + thread_id_ = 0; +#endif + } /** - * Deconstruct the runloop. + * Do one iteration of the runloop. + * \return The number of tasks which were given time. */ - ~runloop(); - + int run_once(); /** * Start running the runloop. @@ -64,26 +64,20 @@ public: */ void stop(int code = 0); + bool is_running() const + { + return !stop_; + } - /** Get the runloop of the current thread. - * \return The current runloop or 0 if none is running in the current - * thread. - */ - static runloop* current(); - + void add_timer(timer& timer); + void remove_timer(timer& timer); private: - friend class timer; - - void add_timer(timer* timer); - void remove_timer(timer* timer); - - bool stop_; - int code_; + int code_; - typedef std::set timer_table; + typedef std::vector timer_table; timer_table timers_; timer_table::iterator timers_it_; @@ -91,9 +85,6 @@ private: MOOF_DECLARE_MUTEX(timers_mutex_); uint32_t thread_id_; #endif - - - backend backend_; };