[pulseaudio-commits] r1145 - /trunk/src/pulse/glib-mainloop.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Tue Jul 25 13:09:23 PDT 2006


Author: lennart
Date: Tue Jul 25 22:09:22 2006
New Revision: 1145

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1145&root=pulseaudio&view=rev
Log:
add a few more g_assert()s and change all assert()s to g_assert()s

Modified:
    trunk/src/pulse/glib-mainloop.c

Modified: trunk/src/pulse/glib-mainloop.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulse/glib-mainloop.c?rev=1145&root=pulseaudio&r1=1144&r2=1145&view=diff
==============================================================================
--- trunk/src/pulse/glib-mainloop.c (original)
+++ trunk/src/pulse/glib-mainloop.c Tue Jul 25 22:09:22 2006
@@ -106,8 +106,10 @@
         if (force || e->dead) {
             PA_LLIST_REMOVE(pa_io_event, g->io_events, e);
 
-            if (e->dead)
+            if (e->dead) {
+                g_assert(g->io_events_please_scan > 0);
                 g->io_events_please_scan--;
+            }
             
             if (e->poll_fd_added)
                 g_source_remove_poll(&g->source, &e->poll_fd);
@@ -121,7 +123,7 @@
         e = n;
     }
 
-    assert(g->io_events_please_scan == 0);
+    g_assert(g->io_events_please_scan == 0);
 }
 
 static void cleanup_time_events(pa_glib_mainloop *g, int force) {
@@ -137,11 +139,15 @@
         if (force || e->dead) {
             PA_LLIST_REMOVE(pa_time_event, g->time_events, e);
 
-            if (e->dead)
+            if (e->dead) {
+                g_assert(g->time_events_please_scan > 0);
                 g->time_events_please_scan--;
-
-            if (!e->dead && e->enabled)
+            }
+
+            if (!e->dead && e->enabled) {
+                g_assert(g->n_enabled_time_events > 0);
                 g->n_enabled_time_events--;
+            }
             
             if (e->destroy_callback)
                 e->destroy_callback(&g->api, e, e->userdata);
@@ -152,7 +158,7 @@
         e = n;
     }
 
-    assert(g->time_events_please_scan == 0);
+    g_assert(g->time_events_please_scan == 0);
 }
 
 static void cleanup_defer_events(pa_glib_mainloop *g, int force) {
@@ -168,11 +174,15 @@
         if (force || e->dead) {
             PA_LLIST_REMOVE(pa_defer_event, g->defer_events, e);
 
-            if (e->dead)
+            if (e->dead) {
+                g_assert(g->defer_events_please_scan > 0);
                 g->defer_events_please_scan--;
-
-            if (!e->dead && e->enabled)
+            }
+
+            if (!e->dead && e->enabled) {
+                g_assert(g->n_enabled_defer_events > 0);
                 g->n_enabled_defer_events--;
+            }
             
             if (e->destroy_callback)
                 e->destroy_callback(&g->api, e, e->userdata);
@@ -183,7 +193,7 @@
         e = n;
     }
 
-    assert(g->defer_events_please_scan == 0);
+    g_assert(g->defer_events_please_scan == 0);
 }
 
 static gushort map_flags_to_glib(pa_io_event_flags_t flags) {
@@ -212,10 +222,10 @@
     pa_io_event *e;
     pa_glib_mainloop *g;
 
-    assert(m);
-    assert(m->userdata);
-    assert(fd >= 0);
-    assert(cb);
+    g_assert(m);
+    g_assert(m->userdata);
+    g_assert(fd >= 0);
+    g_assert(cb);
     
     g = m->userdata;
 
@@ -240,15 +250,15 @@
 }
 
 static void glib_io_enable(pa_io_event*e, pa_io_event_flags_t f) {
-    assert(e);
-    assert(!e->dead);
+    g_assert(e);
+    g_assert(!e->dead);
 
     e->poll_fd.events = map_flags_to_glib(f);
 }
 
 static void glib_io_free(pa_io_event*e) {
-    assert(e);
-    assert(!e->dead);
+    g_assert(e);
+    g_assert(!e->dead);
 
     e->dead = 1;
     e->mainloop->io_events_please_scan++;
@@ -260,8 +270,8 @@
 }
 
 static void glib_io_set_destroy(pa_io_event*e, pa_io_event_destroy_cb_t cb) {
-    assert(e);
-    assert(!e->dead);
+    g_assert(e);
+    g_assert(!e->dead);
     
     e->destroy_callback = cb;
 }
@@ -277,9 +287,9 @@
     pa_glib_mainloop *g;
     pa_time_event *e;
     
-    assert(m);
-    assert(m->userdata);
-    assert(cb);
+    g_assert(m);
+    g_assert(m->userdata);
+    g_assert(cb);
     
     g = m->userdata;
 
@@ -309,20 +319,21 @@
 }
 
 static void glib_time_restart(pa_time_event*e, const struct timeval *tv) {
-    assert(e);
-    assert(!e->dead);
-
-    if (e->enabled && !tv)
+    g_assert(e);
+    g_assert(!e->dead);
+
+    if (e->enabled && !tv) {
+        g_assert(e->mainloop->n_enabled_time_events > 0);
         e->mainloop->n_enabled_time_events--;
-    else if (!e->enabled && tv)
+    } else if (!e->enabled && tv)
         e->mainloop->n_enabled_time_events++;
 
-    if ((e->enabled = !!tv))
+    if ((e->enabled = !!tv)) 
         e->timeval = *tv;
 
     if (e->mainloop->cached_next_time_event && e->enabled) {
         g_assert(e->mainloop->cached_next_time_event->enabled);
-
+            
         if (pa_timeval_cmp(tv, &e->mainloop->cached_next_time_event->timeval) < 0)
             e->mainloop->cached_next_time_event = e;
     } else if (e->mainloop->cached_next_time_event == e)
@@ -330,8 +341,8 @@
  }
 
 static void glib_time_free(pa_time_event *e) {
-    assert(e);
-    assert(!e->dead);
+    g_assert(e);
+    g_assert(!e->dead);
 
     e->dead = 1;
     e->mainloop->time_events_please_scan++;
@@ -344,8 +355,8 @@
 }
 
 static void glib_time_set_destroy(pa_time_event *e, pa_time_event_destroy_cb_t cb) {
-    assert(e);
-    assert(!e->dead);
+    g_assert(e);
+    g_assert(!e->dead);
     
     e->destroy_callback = cb;
 }
@@ -360,9 +371,9 @@
     pa_defer_event *e;
     pa_glib_mainloop *g;
 
-    assert(m);
-    assert(m->userdata);
-    assert(cb);
+    g_assert(m);
+    g_assert(m->userdata);
+    g_assert(cb);
     
     g = m->userdata;
     
@@ -382,31 +393,34 @@
 }
 
 static void glib_defer_enable(pa_defer_event *e, int b) {
-    assert(e);
-    assert(!e->dead);
-
-    if (e->enabled && !b)
+    g_assert(e);
+    g_assert(!e->dead);
+
+    if (e->enabled && !b) {
+        g_assert(e->mainloop->n_enabled_defer_events > 0);
         e->mainloop->n_enabled_defer_events--;
-    else if (!e->enabled && b)
+    } else if (!e->enabled && b)
         e->mainloop->n_enabled_defer_events++;
 
     e->enabled = b;
 }
 
 static void glib_defer_free(pa_defer_event *e) {
-    assert(e);
-    assert(!e->dead);
+    g_assert(e);
+    g_assert(!e->dead);
 
     e->dead = 1;
     e->mainloop->defer_events_please_scan++;
 
-    if (e->enabled)
+    if (e->enabled) {
+        g_assert(e->mainloop->n_enabled_defer_events > 0);
         e->mainloop->n_enabled_defer_events--;
+    }
 }
 
 static void glib_defer_set_destroy(pa_defer_event *e, pa_defer_event_destroy_cb_t cb) {
-    assert(e);
-    assert(!e->dead);
+    g_assert(e);
+    g_assert(!e->dead);
 
     e->destroy_callback = cb;
 }
@@ -422,7 +436,7 @@
 
 static pa_time_event* find_next_time_event(pa_glib_mainloop *g) {
     pa_time_event *t, *n = NULL;
-    assert(g);
+    g_assert(g);
 
     if (g->cached_next_time_event)
         return g->cached_next_time_event;
@@ -445,20 +459,26 @@
     return n;
 }
 
+static void scan_dead(pa_glib_mainloop *g) {
+    g_assert(g);
+    
+    if (g->io_events_please_scan)
+        cleanup_io_events(g, 0);
+
+    if (g->time_events_please_scan)
+        cleanup_time_events(g, 0);
+
+    if (g->defer_events_please_scan)
+        cleanup_defer_events(g, 0);
+}
+
 static gboolean prepare_func(GSource *source, gint *timeout) {
     pa_glib_mainloop *g = (pa_glib_mainloop*) source;
 
     g_assert(g);
     g_assert(timeout);
 
-    if (g->io_events_please_scan)
-        cleanup_io_events(g, 0);
-
-    if (g->time_events_please_scan)
-        cleanup_time_events(g, 0);
-
-    if (g->defer_events_please_scan)
-        cleanup_defer_events(g, 0);
+    scan_dead(g);
 
     if (g->n_enabled_defer_events) {
         *timeout = 0;
@@ -534,7 +554,7 @@
             break;
         }
 
-        assert(d);
+        g_assert(d);
         
         d->callback(&g->api, d, d->userdata);
         return TRUE;
@@ -553,6 +573,7 @@
         tvnow.tv_usec = now.tv_usec;
 
         if (pa_timeval_cmp(&t->timeval, &tvnow) <= 0) {
+            t->enabled = 0;
             t->callback(&g->api, t, &t->timeval, t->userdata);
             return TRUE;
         }
@@ -621,7 +642,7 @@
 }
 
 void pa_glib_mainloop_free(pa_glib_mainloop* g) {
-    assert(g);
+    g_assert(g);
 
     cleanup_io_events(g, 1);
     cleanup_defer_events(g, 1);
@@ -633,7 +654,7 @@
 }
 
 pa_mainloop_api* pa_glib_mainloop_get_api(pa_glib_mainloop *g) {
-    assert(g);
+    g_assert(g);
     
     return &g->api;
 }




More information about the pulseaudio-commits mailing list