* rework reference counting in the client libraries: now refcounting goes

strictly "one-way" - the "bigger" object refcounts the "smaller" one, never the
  other way round. 

* when registering for a reply packet in pdispatch, specify a function that is
  called when the pdispatch object is destroyed but the reply hasn't yet been
  recieved.

* move prototype of pa_free_cb from stream.h to def.h 



git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@794 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2006-04-24 19:29:15 +00:00
parent d26621371e
commit 820c118f9c
12 changed files with 175 additions and 116 deletions

View file

@ -97,6 +97,7 @@ struct reply_info {
PA_LLIST_FIELDS(struct reply_info);
pa_pdispatch_cb_t callback;
void *userdata;
pa_free_cb_t free_cb;
uint32_t tag;
pa_time_event *time_event;
};
@ -145,8 +146,12 @@ pa_pdispatch* pa_pdispatch_new(pa_mainloop_api *mainloop, const pa_pdispatch_cb_
static void pdispatch_free(pa_pdispatch *pd) {
assert(pd);
while (pd->replies)
while (pd->replies) {
if (pd->replies->free_cb)
pd->replies->free_cb(pd->replies->userdata);
reply_info_free(pd->replies);
}
pa_xfree(pd);
}
@ -243,7 +248,7 @@ static void timeout_callback(pa_mainloop_api*m, pa_time_event*e, PA_GCC_UNUSED c
run_action(r->pdispatch, r, PA_COMMAND_TIMEOUT, NULL);
}
void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa_pdispatch_cb_t cb, void *userdata) {
void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa_pdispatch_cb_t cb, void *userdata, pa_free_cb_t free_cb) {
struct reply_info *r;
struct timeval tv;
assert(pd && pd->ref >= 1 && cb);
@ -252,6 +257,7 @@ void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa
r->pdispatch = pd;
r->callback = cb;
r->userdata = userdata;
r->free_cb = free_cb;
r->tag = tag;
pa_gettimeofday(&tv);

View file

@ -24,6 +24,7 @@
#include <inttypes.h>
#include <polyp/mainloop-api.h>
#include <polyp/def.h>
#include <polypcore/tagstruct.h>
#include <polypcore/packet.h>
@ -38,7 +39,7 @@ pa_pdispatch* pa_pdispatch_ref(pa_pdispatch *pd);
int pa_pdispatch_run(pa_pdispatch *pd, pa_packet*p, const void*creds, void *userdata);
void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa_pdispatch_cb_t callback, void *userdata);
void pa_pdispatch_register_reply(pa_pdispatch *pd, uint32_t tag, int timeout, pa_pdispatch_cb_t callback, void *userdata, pa_free_cb_t free_cb);
int pa_pdispatch_is_pending(pa_pdispatch *pd);