X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2Fmoof%2Frunloop.cc;h=98bc3a22cad4b1b2b46b1258b9fe3d03fb999e5a;hp=f6f47dd6f87d1f7029970e3802be6eddd6bd1aed;hb=6c9943707d4f33035830eba0587a61a34eaecbc2;hpb=af88821a172c4dfd138b91b2a5148ae50b502fa2 diff --git a/src/moof/runloop.cc b/src/moof/runloop.cc index f6f47dd..98bc3a2 100644 --- a/src/moof/runloop.cc +++ b/src/moof/runloop.cc @@ -22,104 +22,48 @@ namespace moof { -enum registry_action +bool comp(timer* a, timer* b) { - lookup, - set -}; + return a->expiration() < b->expiration(); +} -static uint32_t call_registry(runloop*& runloop, registry_action action) +void runloop::run_once() { #if ENABLE_THREADS - typedef stlplus::hash table_t; - static table_t table; - - uint32_t thread_id = thread::current_identifier(); - - MOOF_DECLARE_STATIC_MUTEX(table_mutex); - MOOF_MUTEX_LOCK(table_mutex); + thread_id_ = thread::current_identifier(); +#endif - switch (action) + //log_debug("------------------------------------"); + //scalar next_event = SCALAR(0.0); { - case set: - { - log_info("registering runloop", runloop, "for thread", thread_id); - if (runloop) table[thread_id] = runloop; - else table.erase(thread_id); - break; - } + MOOF_MUTEX_LOCK(timers_mutex_); - case lookup: + for (timers_it_ = timers_.begin(); + timers_it_ != timers_.end(); + ++timers_it_) { - table_t::iterator it = table.find(thread_id); - if (it != table.end()) runloop = (*it).second; - else log_warning("runloop is not in registry for thread", thread_id); - break; + (*timers_it_)->fire_if_expired(); } - } - return thread_id; -#else - return thread::current_identifier(); -#endif -} - -bool comp(timer* a, timer* b) -{ - return a->expiration() < b->expiration(); + std::sort(timers_.begin(), timers_.end(), comp); + //next_event = timers_[0]->expiration(); + } } int runloop::run() { -#if ENABLE_THREADS - runloop* runloop = this; - thread_id_ = call_registry(runloop, set); -#endif - stop_ = false; while (!stop_) { - log_debug("------------------------------------"); - scalar next_event = SCALAR(0.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(); - - //for (timers_it_ = timers_.begin(); - //timers_it_ != timers_.end(); - //++timers_it_) - //{ - //scalar absolute = (*timers_it_)->fire_if_expired(); - //if (next_event == SCALAR(0.0) || - //(absolute != SCALAR(0.0) && absolute < next_event)) - //{ - //next_event = absolute; - //} - //} - } - timer::sleep(next_event, timer::absolute); + run_once(); + //timer::sleep(next_event, timer::absolute); + timer::sleep(SCALAR(0.0)); } return code_; } -runloop::~runloop() -{ - runloop* runloop = 0; - call_registry(runloop, set); -} - - void runloop::stop(int code) { code_ = code; @@ -127,14 +71,6 @@ void runloop::stop(int code) } -runloop* runloop::current() -{ - runloop* runloop; - call_registry(runloop, lookup); - return runloop; -} - - void runloop::add_timer(timer& timer) { #if ENABLE_THREADS