4 This file is part of polypaudio.
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 polypaudio 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 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
34 static void stat_add(pa_memblock*m, pa_memblock_stat *s) {
42 m->stat = pa_memblock_stat_ref(s);
45 s->total_size += m->length;
46 s->allocated_size += m->length;
49 static void stat_remove(pa_memblock *m) {
56 m->stat->total_size -= m->length;
58 pa_memblock_stat_unref(m->stat);
62 pa_memblock *pa_memblock_new(size_t length, pa_memblock_stat*s) {
63 pa_memblock *b = pa_xmalloc(sizeof(pa_memblock)+length);
64 b->type = PA_MEMBLOCK_APPENDED;
74 pa_memblock *pa_memblock_new_dynamic(void *d, size_t length, pa_memblock_stat*s) {
75 pa_memblock *b = pa_xmalloc(sizeof(pa_memblock));
76 b->type = PA_MEMBLOCK_DYNAMIC;
86 pa_memblock *pa_memblock_new_fixed(void *d, size_t length, int read_only, pa_memblock_stat*s) {
87 pa_memblock *b = pa_xmalloc(sizeof(pa_memblock));
88 b->type = PA_MEMBLOCK_FIXED;
93 b->read_only = read_only;
98 pa_memblock *pa_memblock_new_user(void *d, size_t length, void (*free_cb)(void *p), int read_only, pa_memblock_stat*s) {
100 assert(d && length && free_cb);
101 b = pa_xmalloc(sizeof(pa_memblock));
102 b->type = PA_MEMBLOCK_USER;
106 b->free_cb = free_cb;
107 b->read_only = read_only;
112 pa_memblock* pa_memblock_ref(pa_memblock*b) {
113 assert(b && b->ref >= 1);
118 void pa_memblock_unref(pa_memblock*b) {
119 assert(b && b->ref >= 1);
121 if ((--(b->ref)) == 0) {
124 if (b->type == PA_MEMBLOCK_USER) {
127 } else if (b->type == PA_MEMBLOCK_DYNAMIC)
134 void pa_memblock_unref_fixed(pa_memblock *b) {
135 assert(b && b->ref >= 1 && b->type == PA_MEMBLOCK_FIXED);
138 pa_memblock_unref(b);
140 b->data = pa_xmemdup(b->data, b->length);
141 b->type = PA_MEMBLOCK_DYNAMIC;
146 pa_memblock_stat* pa_memblock_stat_new(void) {
149 s = pa_xmalloc(sizeof(pa_memblock_stat));
151 s->total = s->total_size = s->allocated = s->allocated_size = 0;
156 void pa_memblock_stat_unref(pa_memblock_stat *s) {
157 assert(s && s->ref >= 1);
165 pa_memblock_stat * pa_memblock_stat_ref(pa_memblock_stat *s) {