[pulseaudio-commits] r1700 - in /branches/lennart/src/pulsecore: rtpoll.c rtpoll.h
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Wed Aug 22 10:11:27 PDT 2007
Author: lennart
Date: Wed Aug 22 19:11:26 2007
New Revision: 1700
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1700&root=3Dpulseaudio&vi=
ew=3Drev
Log:
add convenience functions to hook up pa_fdsem and pa_asyncmsgq to an pa_rtp=
oll; add pa_rtpoll_item_get_userdata(), on EINTR/EAGAIN, reset revents; aut=
omatically destory left over items
Modified:
branches/lennart/src/pulsecore/rtpoll.c
branches/lennart/src/pulsecore/rtpoll.h
Modified: branches/lennart/src/pulsecore/rtpoll.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
rtpoll.c?rev=3D1700&root=3Dpulseaudio&r1=3D1699&r2=3D1700&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/rtpoll.c (original)
+++ branches/lennart/src/pulsecore/rtpoll.c Wed Aug 22 19:11:26 2007
@@ -241,7 +241,9 @@
void pa_rtpoll_free(pa_rtpoll *p) {
pa_assert(p);
=
- pa_assert(!p->items);
+ while (p->items)
+ rtpoll_item_destroy(p->items);
+ =
pa_xfree(p->pollfd);
pa_xfree(p->pollfd2);
=
@@ -256,6 +258,8 @@
int pa_rtpoll_run(pa_rtpoll *p) {
pa_rtpoll_item *i;
int r =3D 0;
+ int no_events =3D 0;
+ int saved_errno;
=
pa_assert(p);
pa_assert(!p->running);
@@ -308,8 +312,12 @@
r =3D poll(p->pollfd, p->n_pollfd_used, p->interval > 0 ? p->inter=
val / 1000 : -1);
#endif
=
- if (r < 0 && (errno =3D=3D EAGAIN || errno =3D=3D EINTR))
+ saved_errno =3D errno;
+ =
+ if (r < 0 && (errno =3D=3D EAGAIN || errno =3D=3D EINTR)) {
r =3D 0;
+ no_events =3D 1;
+ }
=
for (i =3D p->items; i; i =3D i->next) {
=
@@ -319,6 +327,13 @@
if (!i->after_cb)
continue;
=
+ if (no_events) {
+ unsigned j;
+
+ for (j =3D 0; j < i->n_pollfd; j++)
+ i->pollfd[j].revents =3D 0;
+ }
+ =
i->after_cb(i);
}
=
@@ -338,6 +353,8 @@
rtpoll_item_destroy(i);
}
}
+
+ errno =3D saved_errno;
=
return r;
}
@@ -452,3 +469,68 @@
=
i->userdata =3D userdata;
}
+
+void* pa_rtpoll_item_get_userdata(pa_rtpoll_item *i) {
+ pa_assert(i);
+
+ return i->userdata;
+}
+
+static int fdsem_before(pa_rtpoll_item *i) {
+ return pa_fdsem_before_poll(i->userdata);
+}
+
+static void fdsem_after(pa_rtpoll_item *i) {
+ pa_assert((i->pollfd[0].revents & ~POLLIN) =3D=3D 0);
+ pa_fdsem_after_poll(i->userdata);
+}
+
+pa_rtpoll_item *pa_rtpoll_item_new_fdsem(pa_rtpoll *p, pa_fdsem *f) {
+ pa_rtpoll_item *i;
+ struct pollfd *pollfd;
+ =
+ pa_assert(p);
+ pa_assert(f);
+
+ i =3D pa_rtpoll_item_new(p, 1);
+
+ pollfd =3D pa_rtpoll_item_get_pollfd(i, NULL);
+
+ pollfd->fd =3D pa_fdsem_get(f);
+ pollfd->events =3D POLLIN;
+ =
+ i->before_cb =3D fdsem_before;
+ i->after_cb =3D fdsem_after;
+ i->userdata =3D f;
+
+ return i;
+}
+
+static int asyncmsgq_before(pa_rtpoll_item *i) {
+ return pa_asyncmsgq_before_poll(i->userdata);
+}
+
+static void asyncmsgq_after(pa_rtpoll_item *i) {
+ pa_assert((i->pollfd[0].revents & ~POLLIN) =3D=3D 0);
+ pa_asyncmsgq_after_poll(i->userdata);
+}
+
+pa_rtpoll_item *pa_rtpoll_item_new_asyncmsgq(pa_rtpoll *p, pa_asyncmsgq *q=
) {
+ pa_rtpoll_item *i;
+ struct pollfd *pollfd;
+ =
+ pa_assert(p);
+ pa_assert(q);
+
+ i =3D pa_rtpoll_item_new(p, 1);
+
+ pollfd =3D pa_rtpoll_item_get_pollfd(i, NULL);
+ pollfd->fd =3D pa_asyncmsgq_get_fd(q);
+ pollfd->events =3D POLLIN;
+ =
+ i->before_cb =3D asyncmsgq_before;
+ i->after_cb =3D asyncmsgq_after;
+ i->userdata =3D q;
+
+ return i;
+}
Modified: branches/lennart/src/pulsecore/rtpoll.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
rtpoll.h?rev=3D1700&root=3Dpulseaudio&r1=3D1699&r2=3D1700&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/rtpoll.h (original)
+++ branches/lennart/src/pulsecore/rtpoll.h Wed Aug 22 19:11:26 2007
@@ -28,6 +28,8 @@
#include <sys/types.h>
=
#include <pulse/sample.h>
+#include <pulsecore/asyncmsgq.h>
+#include <pulsecore/fdsem.h>
=
/* An implementation of a "real-time" poll loop. Basically, this is
* yet another wrapper around poll(). However it has certain
@@ -67,5 +69,10 @@
void pa_rtpoll_item_set_before_callback(pa_rtpoll_item *i, int (*before_cb=
)(pa_rtpoll_item *i));
void pa_rtpoll_item_set_after_callback(pa_rtpoll_item *i, void (*after_cb)=
(pa_rtpoll_item *i));
void pa_rtpoll_item_set_userdata(pa_rtpoll_item *i, void *userdata);
+void* pa_rtpoll_item_get_userdata(pa_rtpoll_item *i);
+
+pa_rtpoll_item *pa_rtpoll_item_new_fdsem(pa_rtpoll *p, pa_fdsem *s);
+pa_rtpoll_item *pa_rtpoll_item_new_asyncmsgq(pa_rtpoll *p, pa_asyncmsgq *q=
);
+
=
#endif
More information about the pulseaudio-commits
mailing list