summaryrefslogtreecommitdiffstats
path: root/src/polyp
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-04-12 22:45:57 +0000
committerLennart Poettering <lennart@poettering.net>2006-04-12 22:45:57 +0000
commitbf88854e60500f251fefbde8ab678b9d93280201 (patch)
tree7562aaf230b17531bb3f8d4346002e569091ebf8 /src/polyp
parent853caf12740ed3ff4f4c64c2cb458cb0cc635d25 (diff)
* 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 git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@690 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'src/polyp')
-rw-r--r--src/polyp/mainloop.c125
-rw-r--r--src/polyp/mainloop.h5
-rw-r--r--src/polyp/simple.c35
3 files changed, 80 insertions, 85 deletions
diff --git a/src/polyp/mainloop.c b/src/polyp/mainloop.c
index 95c336e4..da3f57b2 100644
--- a/src/polyp/mainloop.c
+++ b/src/polyp/mainloop.c
@@ -624,83 +624,95 @@ static void clear_wakeup(pa_mainloop *m) {
}
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->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;
+ 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 dispatched;
+ return 0;
quit:
-
m->state = STATE_QUIT;
-
return -2;
}
int pa_mainloop_poll(pa_mainloop *m) {
int r;
- assert(m && (m->state == STATE_PREPARED));
+ assert(m);
+ assert(m->state == STATE_PREPARED);
- m->state = STATE_POLLING;
+ if (m->quit)
+ goto quit;
- r = poll(m->pollfds, m->n_pollfds, m->prepared_timeout);
+ m->state = STATE_POLLING;
- if ((r < 0) && (errno == EINTR))
- r = 0;
+ if (m->deferred_pending)
+ r = 0;
+ else {
+ r = poll(m->pollfds, m->n_pollfds, m->prepared_timeout);
- if (r < 0)
- m->state = STATE_PASSIVE;
- else
- m->state = STATE_POLLED;
+ 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_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_get_retval(pa_mainloop *m) {
}
int pa_mainloop_iterate(pa_mainloop *m, int block, int *retval) {
- int r, dispatched = 0;
-
+ int r;
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;
+ if ((r = pa_mainloop_prepare(m, block ? -1 : 0)) < 0)
+ goto quit;
- r = pa_mainloop_poll(m);
- if (r < 0) {
- pa_log(__FILE__": poll(): %s", strerror(errno));
- return r;
- }
+ if ((r = pa_mainloop_poll(m)) < 0)
+ goto quit;
- r = pa_mainloop_dispatch(m);
- if (r < 0) {
- if ((r == -2) && retval)
- *retval = pa_mainloop_get_retval(m);
- return r;
- }
+ if ((r = pa_mainloop_dispatch(m)) < 0)
+ goto quit;
- dispatched += r;
+ return r;
- return dispatched;
+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)
@@ -764,12 +767,6 @@ pa_mainloop_api* pa_mainloop_get_api(pa_mainloop*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) {
assert(m);
diff --git a/src/polyp/mainloop.h b/src/polyp/mainloop.h
index c06b47d0..82d1adc4 100644
--- a/src/polyp/mainloop.h
+++ b/src/polyp/mainloop.h
@@ -107,12 +107,9 @@ int pa_mainloop_iterate(pa_mainloop *m, int block, int *retval);
/** 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);
diff --git a/src/polyp/simple.c b/src/polyp/simple.c
index f48c0b17..dbf7a325 100644
--- a/src/polyp/simple.c
+++ b/src/polyp/simple.c
@@ -91,31 +91,32 @@ static int iterate(pa_simple *p, int block, int *rerror) {
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 (rerror)
- *rerror = PA_ERR_INTERNAL;
- return -1;
- }
- if (check_error(p, rerror) < 0)
- return -1;
-
- } while (pa_context_is_pending(p->context));
+ 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));
+ }
-
- while (pa_mainloop_deferred_pending(p->mainloop)) {
+ for (;;) {
+ int r;
- if (pa_mainloop_iterate(p->mainloop, 0, NULL) < 0) {
+ if ((r = 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;
}