[pulseaudio-commits] r1635 - in /branches/lennart/src: pulsecore/asyncmsgq.c pulsecore/asyncmsgq.h pulsecore/thread-mq.c tests/asyncmsgq-test.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Sat Aug 11 09:01:26 PDT 2007
Author: lennart
Date: Sat Aug 11 18:01:25 2007
New Revision: 1635
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1635&root=3Dpulseaudio&vi=
ew=3Drev
Log:
add proper refcounting to pa_asyncmsgq objects, to allow destruction from t=
he dispatched callbacks
Modified:
branches/lennart/src/pulsecore/asyncmsgq.c
branches/lennart/src/pulsecore/asyncmsgq.h
branches/lennart/src/pulsecore/thread-mq.c
branches/lennart/src/tests/asyncmsgq-test.c
Modified: branches/lennart/src/pulsecore/asyncmsgq.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
asyncmsgq.c?rev=3D1635&root=3Dpulseaudio&r1=3D1634&r2=3D1635&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/asyncmsgq.c (original)
+++ branches/lennart/src/pulsecore/asyncmsgq.c Sat Aug 11 18:01:25 2007
@@ -53,6 +53,7 @@
};
=
struct pa_asyncmsgq {
+ PA_REFCNT_DECLARE;
pa_asyncq *asyncq;
pa_mutex *mutex; /* only for the writer side */
=
@@ -64,6 +65,7 @@
=
a =3D pa_xnew(pa_asyncmsgq, 1);
=
+ PA_REFCNT_INIT(a);
pa_assert_se(a->asyncq =3D pa_asyncq_new(size));
pa_assert_se(a->mutex =3D pa_mutex_new(0));
a->current =3D NULL;
@@ -71,7 +73,7 @@
return a;
}
=
-void pa_asyncmsgq_free(pa_asyncmsgq *a) {
+static void asyncmsgq_free(pa_asyncmsgq *a) {
struct asyncmsgq_item *i;
pa_assert(a);
=
@@ -97,9 +99,23 @@
pa_xfree(a);
}
=
+pa_asyncmsgq* pa_asyncmsgq_ref(pa_asyncmsgq *q) {
+ pa_assert(PA_REFCNT_VALUE(q) > 0);
+
+ PA_REFCNT_INC(q);
+ return q;
+}
+
+void pa_asyncmsgq_unref(pa_asyncmsgq* q) {
+ pa_assert(PA_REFCNT_VALUE(q) > 0);
+
+ if (PA_REFCNT_DEC(q) <=3D 0)
+ asyncmsgq_free(q);
+}
+
void pa_asyncmsgq_post(pa_asyncmsgq *a, pa_msgobject *object, int code, co=
nst void *userdata, int64_t offset, const pa_memchunk *chunk, pa_free_cb_t =
free_cb) {
struct asyncmsgq_item *i;
- pa_assert(a);
+ pa_assert(PA_REFCNT_VALUE(a) > 0);
=
if (!(i =3D pa_flist_pop(PA_STATIC_FLIST_GET(asyncmsgq))))
i =3D pa_xnew(struct asyncmsgq_item, 1);
@@ -125,7 +141,7 @@
=
int pa_asyncmsgq_send(pa_asyncmsgq *a, pa_msgobject *object, int code, con=
st void *userdata, int64_t offset, const pa_memchunk *chunk) {
struct asyncmsgq_item i;
- pa_assert(a);
+ pa_assert(PA_REFCNT_VALUE(a) > 0);
=
i.code =3D code;
i.object =3D object;
@@ -152,7 +168,7 @@
}
=
int pa_asyncmsgq_get(pa_asyncmsgq *a, pa_msgobject **object, int *code, vo=
id **userdata, int64_t *offset, pa_memchunk *chunk, int wait) {
- pa_assert(a);
+ pa_assert(PA_REFCNT_VALUE(a) > 0);
pa_assert(code);
pa_assert(!a->current);
=
@@ -181,6 +197,7 @@
}
=
void pa_asyncmsgq_done(pa_asyncmsgq *a, int ret) {
+ pa_assert(PA_REFCNT_VALUE(a) > 0);
pa_assert(a);
pa_assert(a->current);
=
@@ -207,12 +224,14 @@
=
int pa_asyncmsgq_wait_for(pa_asyncmsgq *a, int code) {
int c;
- pa_assert(a);
+ pa_assert(PA_REFCNT_VALUE(a) > 0);
+
+ pa_asyncmsgq_ref(a);
=
do {
pa_msgobject *o;
void *data;
- int64_t offset;
+ int64_t offset;
pa_memchunk chunk;
int ret;
=
@@ -224,23 +243,25 @@
=
} while (c !=3D code);
=
+ pa_asyncmsgq_unref(a);
+ =
return 0;
}
=
int pa_asyncmsgq_get_fd(pa_asyncmsgq *a) {
- pa_assert(a);
+ pa_assert(PA_REFCNT_VALUE(a) > 0);
=
return pa_asyncq_get_fd(a->asyncq);
}
=
int pa_asyncmsgq_before_poll(pa_asyncmsgq *a) {
- pa_assert(a);
+ pa_assert(PA_REFCNT_VALUE(a) > 0);
=
return pa_asyncq_before_poll(a->asyncq);
}
=
void pa_asyncmsgq_after_poll(pa_asyncmsgq *a) {
- pa_assert(a);
+ pa_assert(PA_REFCNT_VALUE(a) > 0);
=
pa_asyncq_after_poll(a->asyncq);
}
Modified: branches/lennart/src/pulsecore/asyncmsgq.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
asyncmsgq.h?rev=3D1635&root=3Dpulseaudio&r1=3D1634&r2=3D1635&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/asyncmsgq.h (original)
+++ branches/lennart/src/pulsecore/asyncmsgq.h Sat Aug 11 18:01:25 2007
@@ -49,13 +49,14 @@
* latter waits for completion, synchronously. */
=
enum {
- PA_MESSAGE_SHUTDOWN /* A generic message to inform the handler of this=
queue to quit */
+ PA_MESSAGE_SHUTDOWN =3D -1/* A generic message to inform the handler o=
f this queue to quit */
};
=
typedef struct pa_asyncmsgq pa_asyncmsgq;
=
pa_asyncmsgq* pa_asyncmsgq_new(size_t size);
-void pa_asyncmsgq_free(pa_asyncmsgq* q);
+pa_asyncmsgq* pa_asyncmsgq_ref(pa_asyncmsgq *q);
+void pa_asyncmsgq_unref(pa_asyncmsgq* q);
=
void pa_asyncmsgq_post(pa_asyncmsgq *q, pa_msgobject *object, int code, co=
nst void *userdata, int64_t offset, const pa_memchunk *memchunk, pa_free_cb=
_t userdata_free_cb);
int pa_asyncmsgq_send(pa_asyncmsgq *q, pa_msgobject *object, int code, con=
st void *userdata, int64_t offset, const pa_memchunk *memchunk);
Modified: branches/lennart/src/pulsecore/thread-mq.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
thread-mq.c?rev=3D1635&root=3Dpulseaudio&r1=3D1634&r2=3D1635&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/thread-mq.c (original)
+++ branches/lennart/src/pulsecore/thread-mq.c Sat Aug 11 18:01:25 2007
@@ -46,11 +46,13 @@
=
static void asyncmsgq_cb(pa_mainloop_api*api, pa_io_event* e, int fd, pa_i=
o_event_flags_t events, void *userdata) {
pa_thread_mq *q =3D userdata;
+ pa_asyncmsgq *aq;
=
pa_assert(pa_asyncmsgq_get_fd(q->outq) =3D=3D fd);
pa_assert(events =3D=3D PA_IO_EVENT_INPUT);
=
- pa_asyncmsgq_after_poll(q->outq);
+ pa_asyncmsgq_ref(aq =3D q->outq);
+ pa_asyncmsgq_after_poll(aq);
=
for (;;) {
pa_msgobject *object;
@@ -60,16 +62,18 @@
pa_memchunk chunk;
=
/* Check whether there is a message for us to process */
- while (pa_asyncmsgq_get(q->outq, &object, &code, &data, &offset, &=
chunk, 0) =3D=3D 0) {
+ while (pa_asyncmsgq_get(aq, &object, &code, &data, &offset, &chunk=
, 0) =3D=3D 0) {
int ret;
=
ret =3D pa_asyncmsgq_dispatch(object, code, data, offset, &chu=
nk);
- pa_asyncmsgq_done(q->outq, ret);
+ pa_asyncmsgq_done(aq, ret);
}
=
- if (pa_asyncmsgq_before_poll(q->outq) =3D=3D 0)
+ if (pa_asyncmsgq_before_poll(aq) =3D=3D 0)
break;
}
+
+ pa_asyncmsgq_unref(aq);
}
=
void pa_thread_mq_init(pa_thread_mq *q, pa_mainloop_api *mainloop) {
@@ -90,9 +94,8 @@
q->mainloop->io_free(q->io_event);
q->io_event =3D NULL;
=
- pa_asyncmsgq_after_poll(q->outq);
- pa_asyncmsgq_free(q->inq);
- pa_asyncmsgq_free(q->outq);
+ pa_asyncmsgq_unref(q->inq);
+ pa_asyncmsgq_unref(q->outq);
q->inq =3D q->outq =3D NULL;
=
q->mainloop =3D NULL;
Modified: branches/lennart/src/tests/asyncmsgq-test.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/tests/asyn=
cmsgq-test.c?rev=3D1635&root=3Dpulseaudio&r1=3D1634&r2=3D1635&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/tests/asyncmsgq-test.c (original)
+++ branches/lennart/src/tests/asyncmsgq-test.c Sat Aug 11 18:01:25 2007
@@ -104,7 +104,7 @@
=
pa_thread_free(t);
=
- pa_asyncmsgq_free(q);
+ pa_asyncmsgq_unref(q);
=
return 0;
}
More information about the pulseaudio-commits
mailing list