2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2.1 of the License,
9 or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 #include <pulse/xmalloc.h>
27 #include <pulsecore/macro.h>
28 #include <pulsecore/flist.h>
31 #include "operation.h"
33 PA_STATIC_FLIST_DECLARE(operations
, 0, pa_xfree
);
35 pa_operation
*pa_operation_new(pa_context
*c
, pa_stream
*s
, pa_operation_cb_t cb
, void *userdata
) {
39 if (!(o
= pa_flist_pop(PA_STATIC_FLIST_GET(operations
))))
40 o
= pa_xnew(pa_operation
, 1);
47 o
->state
= PA_OPERATION_RUNNING
;
49 o
->userdata
= userdata
;
51 /* Refcounting is strictly one-way: from the "bigger" to the "smaller" object. */
52 PA_LLIST_PREPEND(pa_operation
, c
->operations
, o
);
58 pa_operation
*pa_operation_ref(pa_operation
*o
) {
60 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
66 void pa_operation_unref(pa_operation
*o
) {
68 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
70 if (PA_REFCNT_DEC(o
) <= 0) {
71 pa_assert(!o
->context
);
72 pa_assert(!o
->stream
);
74 if (pa_flist_push(PA_STATIC_FLIST_GET(operations
), o
) < 0)
79 static void operation_unlink(pa_operation
*o
) {
83 pa_assert(PA_REFCNT_VALUE(o
) >= 2);
85 PA_LLIST_REMOVE(pa_operation
, o
->context
->operations
, o
);
86 pa_operation_unref(o
);
96 static void operation_set_state(pa_operation
*o
, pa_operation_state_t st
) {
98 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
107 if ((o
->state
== PA_OPERATION_DONE
) || (o
->state
== PA_OPERATION_CANCELED
))
110 pa_operation_unref(o
);
113 void pa_operation_cancel(pa_operation
*o
) {
115 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
117 operation_set_state(o
, PA_OPERATION_CANCELED
);
120 void pa_operation_done(pa_operation
*o
) {
122 pa_assert(PA_REFCNT_VALUE(o
) >= 1);
124 operation_set_state(o
, PA_OPERATION_DONE
);
127 pa_operation_state_t
pa_operation_get_state(pa_operation
*o
) {
129 pa_assert(PA_REFCNT_VALUE(o
) >= 1);