]>
Dogcows Code - chaz/yoink/blob - src/moof/runloop.cc
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
25 bool comp(timer
* a
, timer
* b
)
27 return a
->expiration() < b
->expiration();
30 void runloop::run_once()
33 thread_id_
= thread::current_identifier();
36 //log_debug("------------------------------------");
37 //scalar next_event = SCALAR(0.0);
39 MOOF_MUTEX_LOCK(timers_mutex_
);
41 for (timers_it_
= timers_
.begin();
42 timers_it_
!= timers_
.end();
45 (*timers_it_
)->fire_if_expired();
48 std::sort(timers_
.begin(), timers_
.end(), comp
);
49 //next_event = timers_[0]->expiration();
59 //timer::sleep(next_event, timer::absolute);
60 timer::sleep(SCALAR(0.0));
67 void runloop::stop(int code
)
74 void runloop::add_timer(timer
& timer
)
77 if (thread_id_
!= thread::current_identifier())
79 MOOF_MUTEX_LOCK(timers_mutex_
);
80 timers_
.push_back(&timer
);
81 timers_it_
= timers_
.end();
86 timers_
.push_back(&timer
);
87 timers_it_
= timers_
.end();
91 void runloop::remove_timer(timer
& timer
)
94 if (thread_id_
!= thread::current_identifier())
96 MOOF_MUTEX_LOCK(timers_mutex_
);
97 timers_
.erase(std::find(timers_
.begin(), timers_
.end(), &timer
));
98 timers_it_
= timers_
.end();
103 timers_
.erase(std::find(timers_
.begin(), timers_
.end(), &timer
));
104 timers_it_
= timers_
.end();
This page took 0.042761 seconds and 5 git commands to generate.