]>
Dogcows Code - chaz/yoink/blob - runloop.cc
db598145f17fbb7f14e40d6b02713109cd67cd94
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 **************************************************************************/
26 static uint32_t call_registry(runloop
*& runloop
, registry_action action
)
28 typedef stlplus::hash
<uint32_t,moof::runloop
*,hash_function
> table_t
;
31 uint32_t thread_id
= thread::current_identifier();
33 static MOOF_DECLARE_MUTEX(table_mutex
);
34 MOOF_MUTEX_LOCK(table_mutex
);
40 if (runloop
) table
[thread_id
] = runloop
;
41 else table
.erase(thread_id
);
47 table_t::iterator it
= table
.find(thread_id
);
48 if (it
!= table
.end()) runloop
= (*it
).second
;
60 runloop
* runloop
= this;
61 thread_id_
= call_registry(runloop
, set
);
67 scalar next_event
= SCALAR(0.0);
69 MOOF_MUTEX_LOCK(timers_mutex_
);
71 for (timers_it_
= timers_
.begin();
72 timers_it_
!= timers_
.end();
75 scalar absolute
= (*timers_it_
)->fire_if_expired();
76 if (next_event
== SCALAR(0.0) ||
77 (absolute
!= SCALAR(0.0) && absolute
< next_event
))
79 next_event
= absolute
;
83 timer::sleep(next_event
, timer::absolute
);
93 call_registry(runloop
, set
);
97 void runloop::stop(int code
)
104 runloop
* runloop::current()
107 call_registry(runloop
, lookup
);
112 void runloop::add_timer(timer
* timer
)
115 if (thread_id_
!= thread::current_identifier())
117 MOOF_MUTEX_LOCK(timers_mutex_
);
118 timers_
.insert(timer
);
119 timers_it_
= timers_
.end();
124 timers_
.insert(timer
);
125 timers_it_
= timers_
.end();
129 void runloop::remove_timer(timer
* timer
)
132 if (thread_id_
!= thread::current_identifier())
134 MOOF_MUTEX_LOCK(timers_mutex_
);
135 timers_
.erase(timer
);
136 timers_it_
= timers_
.end();
141 timers_
.erase(timer
);
142 timers_it_
= timers_
.end();
This page took 0.038993 seconds and 3 git commands to generate.