summaryrefslogtreecommitdiffstats
path: root/src/polyp/operation.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2006-04-24 19:29:15 +0000
committerLennart Poettering <lennart@poettering.net>2006-04-24 19:29:15 +0000
commit820c118f9c57c7a7767765efc802502632ad8da2 (patch)
treedd695cb6183b20ac997907d9c556d98457d827e4 /src/polyp/operation.c
parentd26621371e6bf5040fe833f046ff81a1c7cac94b (diff)
* 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
Diffstat (limited to 'src/polyp/operation.c')
-rw-r--r--src/polyp/operation.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/polyp/operation.c b/src/polyp/operation.c
index 0216888c..1c0cb99f 100644
--- a/src/polyp/operation.c
+++ b/src/polyp/operation.c
@@ -28,78 +28,89 @@
#include <polypcore/xmalloc.h>
#include "internal.h"
-
#include "operation.h"
pa_operation *pa_operation_new(pa_context *c, pa_stream *s, pa_operation_cb_t cb, void *userdata) {
pa_operation *o;
assert(c);
- o = pa_xmalloc(sizeof(pa_operation));
+ o = pa_xnew(pa_operation, 1);
o->ref = 1;
- o->context = pa_context_ref(c);
- o->stream = s ? pa_stream_ref(s) : NULL;
+ o->context = c;
+ o->stream = s;
o->state = PA_OPERATION_RUNNING;
o->callback = cb;
o->userdata = userdata;
- PA_LLIST_PREPEND(pa_operation, o->context->operations, o);
- return pa_operation_ref(o);
+ /* Refcounting is strictly one-way: from the "bigger" to the "smaller" object. */
+ PA_LLIST_PREPEND(pa_operation, c->operations, o);
+ pa_operation_ref(o);
+
+ return o;
}
pa_operation *pa_operation_ref(pa_operation *o) {
- assert(o && o->ref >= 1);
+ assert(o);
+ assert(o->ref >= 1);
+
o->ref++;
return o;
}
void pa_operation_unref(pa_operation *o) {
- assert(o && o->ref >= 1);
+ assert(o);
+ assert(o->ref >= 1);
if ((--(o->ref)) == 0) {
assert(!o->context);
assert(!o->stream);
- free(o);
+ pa_xfree(o);
}
}
static void operation_set_state(pa_operation *o, pa_operation_state_t st) {
- assert(o && o->ref >= 1);
+ assert(o);
+ assert(o->ref >= 1);
if (st == o->state)
return;
- if (!o->context)
- return;
-
o->state = st;
if ((o->state == PA_OPERATION_DONE) || (o->state == PA_OPERATION_CANCELED)) {
- PA_LLIST_REMOVE(pa_operation, o->context->operations, o);
- pa_context_unref(o->context);
- if (o->stream)
- pa_stream_unref(o->stream);
+
+ if (o->context) {
+ assert(o->ref >= 2);
+
+ PA_LLIST_REMOVE(pa_operation, o->context->operations, o);
+ pa_operation_unref(o);
+ }
+
o->context = NULL;
o->stream = NULL;
o->callback = NULL;
o->userdata = NULL;
-
- pa_operation_unref(o);
}
}
void pa_operation_cancel(pa_operation *o) {
- assert(o && o->ref >= 1);
+ assert(o);
+ assert(o->ref >= 1);
+
operation_set_state(o, PA_OPERATION_CANCELED);
}
void pa_operation_done(pa_operation *o) {
- assert(o && o->ref >= 1);
+ assert(o);
+ assert(o->ref >= 1);
+
operation_set_state(o, PA_OPERATION_DONE);
}
pa_operation_state_t pa_operation_get_state(pa_operation *o) {
- assert(o && o->ref >= 1);
+ assert(o);
+ assert(o->ref >= 1);
+
return o->state;
}