Author: toshok
Date: 2007-12-03 19:19:07 -0500 (Mon, 03 Dec 2007)
New Revision: 90610
Modified:
trunk/moon/src/clock.cpp
Log:
instead of duplicating this, abstract it out into 1 place.
Modified: trunk/moon/src/clock.cpp
===================================================================
--- trunk/moon/src/clock.cpp 2007-12-04 00:02:49 UTC (rev 90609)
+++ trunk/moon/src/clock.cpp 2007-12-04 00:19:07 UTC (rev 90610)
@@ -54,7 +54,41 @@
Clock *clock;
};
+typedef void (*ClockFunc)(Clock*);
+void
+clock_list_foreach (GList *clock_list, ClockFunc func)
+{
+ ClockNode *list, *tail, *next;
+ GList *n;
+
+ list = NULL;
+ tail = (ClockNode *) &list;
+
+ for (n = clock_list; n != NULL; n = n->next) {
+ tail->next = g_new (ClockNode, 1);
+ tail = tail->next;
+
+ tail->clock = (Clock *) n->data;
+ tail->clock->ref ();
+ tail->next = NULL;
+ }
+
+ while (list != NULL) {
+ func (list->clock);
+ list->clock->unref ();
+ next = list->next;
+ g_free (list);
+ list = next;
+ }
+}
+
+static void
+CallRaiseAccumulatedEvents (Clock *clock)
+{
+ clock->RaiseAccumulatedEvents ();
+}
+
TimeSpan
get_now (void)
{
@@ -389,28 +423,7 @@
void
TimeManager::RaiseEnqueuedEvents ()
{
- ClockNode *list, *tail, *next;
- GList *n;
-
- list = NULL;
- tail = (ClockNode *) &list;
-
- for (n = child_clocks; n != NULL; n = n->next) {
- tail->next = g_new (ClockNode, 1);
- tail = tail->next;
-
- tail->clock = (Clock *) n->data;
- tail->clock->ref ();
- tail->next = NULL;
- }
-
- while (list != NULL) {
- list->clock->RaiseAccumulatedEvents ();
- list->clock->unref ();
- next = list->next;
- g_free (list);
- list = next;
- }
+ clock_list_foreach (child_clocks, CallRaiseAccumulatedEvents);
}
guint
@@ -1088,33 +1101,12 @@
void
ClockGroup::RaiseAccumulatedEvents ()
{
- ClockNode *list, *tail, *next;
- GList *n;
-
/* raise our events */
this->Clock::RaiseAccumulatedEvents ();
/* now cause our children to raise theirs */
- list = NULL;
- tail = (ClockNode *) &list;
+ clock_list_foreach (child_clocks, CallRaiseAccumulatedEvents);
- for (n = child_clocks; n != NULL; n = n->next) {
- tail->next = g_new (ClockNode, 1);
- tail = tail->next;
-
- tail->clock = (Clock *) n->data;
- tail->clock->ref ();
- tail->next = NULL;
- }
-
- while (list != NULL) {
- list->clock->RaiseAccumulatedEvents ();
- list->clock->unref ();
- next = list->next;
- g_free (list);
- list = next;
- }
-
if (GetHasStarted() && state == Clock::Stopped && !emitted_complete) {
Emit (CompletedEvent);
emitted_complete = true;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches