mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-02 09:01:46 -05:00
* 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
This commit is contained in:
parent
853caf1274
commit
bf88854e60
3 changed files with 81 additions and 86 deletions
|
|
@ -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);
|
||||
|
||||
if (m->quit)
|
||||
goto quit;
|
||||
|
||||
m->state = STATE_POLLING;
|
||||
|
||||
r = poll(m->pollfds, m->n_pollfds, m->prepared_timeout);
|
||||
if (m->deferred_pending)
|
||||
r = 0;
|
||||
else {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
if ((r = pa_mainloop_prepare(m, block ? -1 : 0)) < 0)
|
||||
goto quit;
|
||||
|
||||
dispatched += r;
|
||||
if ((r = pa_mainloop_poll(m)) < 0)
|
||||
goto quit;
|
||||
|
||||
r = pa_mainloop_poll(m);
|
||||
if (r < 0) {
|
||||
pa_log(__FILE__": poll(): %s", strerror(errno));
|
||||
return r;
|
||||
}
|
||||
if ((r = pa_mainloop_dispatch(m)) < 0)
|
||||
goto quit;
|
||||
|
||||
r = pa_mainloop_dispatch(m);
|
||||
if (r < 0) {
|
||||
if ((r == -2) && retval)
|
||||
*retval = pa_mainloop_get_retval(m);
|
||||
return r;
|
||||
}
|
||||
return r;
|
||||
|
||||
dispatched += 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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,30 +91,31 @@ 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 (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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue