]>
Dogcows Code - chaz/yoink/blob - src/moof/runloop.cc
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
8 *****************************************************************************/
25 bool comp(timer
* a
, timer
* b
)
27 return a
->expiration() < b
->expiration();
31 int runloop::run_once()
34 thread_id_
= thread::current_identifier();
37 //log_debug("------------------------------------");
39 MOOF_MUTEX_LOCK(timers_mutex_
);
41 std::sort(timers_
.begin(), timers_
.end(), comp
);
42 for (timers_it_
= timers_
.begin();
43 timers_it_
!= timers_
.end(); ++timers_it_
)
45 if ((*timers_it_
)->fire_if_expired()) ++expired
;
55 if (run_once() == 0);//timer::sleep(SCALAR(0.0));
56 // TODO: maybe sleep(0.0001) will actually return sooner than
57 // sleep(0)... if the kernel interprets sleep(0) as we don't need
58 // to process for an arbitrarily long timespan while specifying a
59 // value lets the kernel know when we need control back...
64 void runloop::stop(int code
)
70 void runloop::add_timer(timer
& timer
)
73 if (thread_id_
!= thread::current_identifier())
75 MOOF_MUTEX_LOCK(timers_mutex_
);
76 timers_
.push_back(&timer
);
77 timers_it_
= timers_
.end();
82 timers_
.push_back(&timer
);
83 timers_it_
= timers_
.end();
87 void runloop::remove_timer(timer
& timer
)
90 if (thread_id_
!= thread::current_identifier())
92 MOOF_MUTEX_LOCK(timers_mutex_
);
93 timers_
.erase(std::find(timers_
.begin(), timers_
.end(), &timer
));
94 timers_it_
= timers_
.end();
99 timers_
.erase(std::find(timers_
.begin(), timers_
.end(), &timer
));
100 timers_it_
= timers_
.end();
This page took 0.040199 seconds and 4 git commands to generate.