[polypaudio-commits] r690 - in /trunk/src/polyp: mainloop.c mainloop.h simple.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Wed Apr 12 15:45:58 PDT 2006
Author: lennart
Date: Thu Apr 13 00:45:57 2006
New Revision: 690
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=690&root=polypaudio&view=rev
Log:
* dispatch defer events in pa_mainloop_dispatch() and not already in pa_mainloop_prepare()
* fix the "timeout" parameter of pa_mainloop_prepare()
* remove pa_mainloop_deferred_pending() and update the simple API accordingly
Modified:
trunk/src/polyp/mainloop.c
trunk/src/polyp/mainloop.h
trunk/src/polyp/simple.c
Modified: trunk/src/polyp/mainloop.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/mainloop.c?rev=690&root=polypaudio&r1=689&r2=690&view=diff
==============================================================================
--- trunk/src/polyp/mainloop.c (original)
+++ trunk/src/polyp/mainloop.c Thu Apr 13 00:45:57 2006
@@ -624,83 +624,95 @@
}
int pa_mainloop_prepare(pa_mainloop *m, int timeout) {
- int dispatched = 0;
-
- assert(m && (m->state == STATE_PASSIVE));
+ assert(m);
+ assert(m->state == STATE_PASSIVE);
clear_wakeup(m);
-
scan_dead(m);
if (m->quit)
goto quit;
- dispatched += dispatch_defer(m);
+ if (!m->deferred_pending) {
+
+ if (m->rebuild_pollfds)
+ rebuild_pollfds(m);
+
+ m->prepared_timeout = calc_next_timeout(m);
+ if (timeout >= 0 && (timeout < m->prepared_timeout || m->prepared_timeout < 0))
+ m->prepared_timeout = timeout;
+ }
+
+ m->state = STATE_PREPARED;
+ return 0;
+
+quit:
+ m->state = STATE_QUIT;
+ return -2;
+}
+
+int pa_mainloop_poll(pa_mainloop *m) {
+ int r;
+
+ assert(m);
+ assert(m->state == STATE_PREPARED);
if (m->quit)
goto quit;
- if (m->rebuild_pollfds)
- rebuild_pollfds(m);
-
- m->prepared_timeout = calc_next_timeout(m);
- if ((timeout >= 0) && (m->prepared_timeout > timeout))
- m->prepared_timeout = timeout;
-
- m->state = STATE_PREPARED;
-
- return dispatched;
+ m->state = STATE_POLLING;
+
+ if (m->deferred_pending)
+ r = 0;
+ else {
+ r = poll(m->pollfds, m->n_pollfds, m->prepared_timeout);
+
+ if (r < 0) {
+ if (errno == EINTR)
+ r = 0;
+ else
+ pa_log(__FILE__": poll(): %s", strerror(errno));
+ }
+ }
+
+ m->state = r < 0 ? STATE_PASSIVE : STATE_POLLED;
+ return r;
quit:
-
m->state = STATE_QUIT;
-
return -2;
-}
-
-int pa_mainloop_poll(pa_mainloop *m) {
- int r;
-
- assert(m && (m->state == STATE_PREPARED));
-
- m->state = STATE_POLLING;
-
- r = poll(m->pollfds, m->n_pollfds, m->prepared_timeout);
-
- if ((r < 0) && (errno == EINTR))
- r = 0;
-
- if (r < 0)
- m->state = STATE_PASSIVE;
- else
- m->state = STATE_POLLED;
-
- return r;
}
int pa_mainloop_dispatch(pa_mainloop *m) {
int dispatched = 0;
- assert(m && (m->state == STATE_POLLED));
-
- dispatched += dispatch_timeout(m);
+ assert(m);
+ assert(m->state == STATE_POLLED);
if (m->quit)
goto quit;
- dispatched += dispatch_pollfds(m);
-
+ if (m->deferred_pending)
+ dispatched += dispatch_defer(m);
+ else {
+ dispatched += dispatch_timeout(m);
+
+ if (m->quit)
+ goto quit;
+
+ dispatched += dispatch_pollfds(m);
+
+ }
+
if (m->quit)
goto quit;
-
+
m->state = STATE_PASSIVE;
return dispatched;
quit:
-
m->state = STATE_QUIT;
-
return -2;
}
@@ -710,39 +722,30 @@
}
int pa_mainloop_iterate(pa_mainloop *m, int block, int *retval) {
- int r, dispatched = 0;
-
- assert(m);
-
- r = pa_mainloop_prepare(m, block ? -1 : 0);
- if (r < 0) {
- if ((r == -2) && retval)
- *retval = pa_mainloop_get_retval(m);
- return r;
- }
-
- dispatched += r;
-
- r = pa_mainloop_poll(m);
- if (r < 0) {
- pa_log(__FILE__": poll(): %s", strerror(errno));
- return r;
- }
-
- r = pa_mainloop_dispatch(m);
- if (r < 0) {
- if ((r == -2) && retval)
- *retval = pa_mainloop_get_retval(m);
- return r;
- }
-
- dispatched += r;
-
- return dispatched;
+ int r;
+ assert(m);
+
+ if ((r = pa_mainloop_prepare(m, block ? -1 : 0)) < 0)
+ goto quit;
+
+ if ((r = pa_mainloop_poll(m)) < 0)
+ goto quit;
+
+ if ((r = pa_mainloop_dispatch(m)) < 0)
+ goto quit;
+
+ return r;
+
+quit:
+
+ if ((r == -2) && retval)
+ *retval = pa_mainloop_get_retval(m);
+ return r;
}
int pa_mainloop_run(pa_mainloop *m, int *retval) {
int r;
+
while ((r = pa_mainloop_iterate(m, 1, retval)) >= 0);
if (r == -2)
@@ -763,12 +766,6 @@
assert(m);
return &m->api;
}
-
-int pa_mainloop_deferred_pending(pa_mainloop *m) {
- assert(m);
- return m->deferred_pending > 0;
-}
-
#if 0
void pa_mainloop_dump(pa_mainloop *m) {
Modified: trunk/src/polyp/mainloop.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/mainloop.h?rev=690&root=polypaudio&r1=689&r2=690&view=diff
==============================================================================
--- trunk/src/polyp/mainloop.h (original)
+++ trunk/src/polyp/mainloop.h Thu Apr 13 00:45:57 2006
@@ -107,11 +107,8 @@
/** Run unlimited iterations of the main loop object until the main loop's quit() routine is called. */
int pa_mainloop_run(pa_mainloop *m, int *retval);
-/** Return the abstract main loop abstraction layer vtable for this main loop. This calls pa_mainloop_iterate() iteratively.*/
+/** Return the abstract main loop abstraction layer vtable for this main loop. */
pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*m);
-
-/** Return non-zero when there are any deferred events pending. \since 0.5 */
-int pa_mainloop_deferred_pending(pa_mainloop *m);
/** Shutdown the main loop */
void pa_mainloop_quit(pa_mainloop *m, int r);
Modified: trunk/src/polyp/simple.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/polyp/simple.c?rev=690&root=polypaudio&r1=689&r2=690&view=diff
==============================================================================
--- trunk/src/polyp/simple.c (original)
+++ trunk/src/polyp/simple.c Thu Apr 13 00:45:57 2006
@@ -91,30 +91,31 @@
if (check_error(p, rerror) < 0)
return -1;
-
- if (!block && !pa_context_is_pending(p->context))
- return 0;
-
- do {
- if (pa_mainloop_iterate(p->mainloop, 1, NULL) < 0) {
+
+ if (block || pa_context_is_pending(p->context)) {
+ do {
+ if (pa_mainloop_iterate(p->mainloop, 1, NULL) < 0) {
+ if (rerror)
+ *rerror = PA_ERR_INTERNAL;
+ return -1;
+ }
+
+ if (check_error(p, rerror) < 0)
+ return -1;
+ } while (pa_context_is_pending(p->context));
+ }
+
+ for (;;) {
+ int r;
+
+ if ((r = pa_mainloop_iterate(p->mainloop, 0, NULL)) < 0) {
if (rerror)
*rerror = PA_ERR_INTERNAL;
return -1;
}
- if (check_error(p, rerror) < 0)
- return -1;
-
- } while (pa_context_is_pending(p->context));
-
-
- while (pa_mainloop_deferred_pending(p->mainloop)) {
-
- if (pa_mainloop_iterate(p->mainloop, 0, NULL) < 0) {
- if (rerror)
- *rerror = PA_ERR_INTERNAL;
- return -1;
- }
+ if (r == 0)
+ break;
if (check_error(p, rerror) < 0)
return -1;
More information about the pulseaudio-commits
mailing list