/*] Copyright (c) 2009-2010, 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 namespace moof { // forward declarations class timer; /** * A runloop is a loop with scheduled timers. */ class runloop : public boost::noncopyable { public: /** * Construct a runloop. */ runloop() : stop_(false) { #if ENABLE_THREADS thread_id_ = 0; #endif } /** * Do one iteration of the runloop. */ void run_once(); /** * Start running the runloop. * \return The exit code. */ int run(); /** * Stop the runloop. * \param code The exit code. */ void stop(int code = 0); void add_timer(timer& timer); void remove_timer(timer& timer); private: bool stop_; int code_; typedef std::vector timer_table; timer_table timers_; timer_table::iterator timers_it_; #if ENABLE_THREADS MOOF_DECLARE_MUTEX(timers_mutex_); uint32_t thread_id_; #endif }; } // namespace moof #endif // _MOOF_RUNLOOP_HH_