modify memory block reference counting to use the new reference counting API

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1342 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Lennart Poettering 2006-08-29 01:16:47 +00:00
parent 9948cb09a3
commit 327e0cd8e1
3 changed files with 18 additions and 15 deletions

View file

@ -170,7 +170,7 @@ static pa_memblock *memblock_new_appended(pa_mempool *p, size_t length) {
b = pa_xmalloc(sizeof(pa_memblock) + length); b = pa_xmalloc(sizeof(pa_memblock) + length);
b->type = PA_MEMBLOCK_APPENDED; b->type = PA_MEMBLOCK_APPENDED;
b->read_only = 0; b->read_only = 0;
b->ref = 1; PA_REFCNT_INIT(b);
b->length = length; b->length = length;
b->data = (uint8_t*) b + sizeof(pa_memblock); b->data = (uint8_t*) b + sizeof(pa_memblock);
b->pool = p; b->pool = p;
@ -253,7 +253,7 @@ pa_memblock *pa_memblock_new_pool(pa_mempool *p, size_t length) {
b->length = length; b->length = length;
b->read_only = 0; b->read_only = 0;
b->ref = 1; PA_REFCNT_INIT(b);
b->pool = p; b->pool = p;
stat_add(b); stat_add(b);
@ -270,7 +270,7 @@ pa_memblock *pa_memblock_new_fixed(pa_mempool *p, void *d, size_t length, int re
b = pa_xnew(pa_memblock, 1); b = pa_xnew(pa_memblock, 1);
b->type = PA_MEMBLOCK_FIXED; b->type = PA_MEMBLOCK_FIXED;
b->read_only = read_only; b->read_only = read_only;
b->ref = 1; PA_REFCNT_INIT(b);
b->length = length; b->length = length;
b->data = d; b->data = d;
b->pool = p; b->pool = p;
@ -290,7 +290,7 @@ pa_memblock *pa_memblock_new_user(pa_mempool *p, void *d, size_t length, void (*
b = pa_xnew(pa_memblock, 1); b = pa_xnew(pa_memblock, 1);
b->type = PA_MEMBLOCK_USER; b->type = PA_MEMBLOCK_USER;
b->read_only = read_only; b->read_only = read_only;
b->ref = 1; PA_REFCNT_INIT(b);
b->length = length; b->length = length;
b->data = d; b->data = d;
b->per_type.user.free_cb = free_cb; b->per_type.user.free_cb = free_cb;
@ -302,17 +302,17 @@ pa_memblock *pa_memblock_new_user(pa_mempool *p, void *d, size_t length, void (*
pa_memblock* pa_memblock_ref(pa_memblock*b) { pa_memblock* pa_memblock_ref(pa_memblock*b) {
assert(b); assert(b);
assert(b->ref >= 1); assert(PA_REFCNT_VALUE(b) > 0);
b->ref++; PA_REFCNT_INC(b);
return b; return b;
} }
void pa_memblock_unref(pa_memblock*b) { void pa_memblock_unref(pa_memblock*b) {
assert(b); assert(b);
assert(b->ref >= 1); assert(PA_REFCNT_VALUE(b) > 0);
if ((--(b->ref)) > 0) if (PA_REFCNT_DEC(b) > 0)
return; return;
stat_remove(b); stat_remove(b);
@ -403,10 +403,10 @@ finish:
void pa_memblock_unref_fixed(pa_memblock *b) { void pa_memblock_unref_fixed(pa_memblock *b) {
assert(b); assert(b);
assert(b->ref >= 1); assert(PA_REFCNT_VALUE(b) > 0);
assert(b->type == PA_MEMBLOCK_FIXED); assert(b->type == PA_MEMBLOCK_FIXED);
if (b->ref > 1) if (PA_REFCNT_VALUE(b) > 1)
memblock_make_local(b); memblock_make_local(b);
pa_memblock_unref(b); pa_memblock_unref(b);
@ -615,7 +615,7 @@ pa_memblock* pa_memimport_get(pa_memimport *i, uint32_t block_id, uint32_t shm_i
b = pa_xnew(pa_memblock, 1); b = pa_xnew(pa_memblock, 1);
b->type = PA_MEMBLOCK_IMPORTED; b->type = PA_MEMBLOCK_IMPORTED;
b->read_only = 1; b->read_only = 1;
b->ref = 1; PA_REFCNT_INIT(b);
b->length = size; b->length = size;
b->data = (uint8_t*) seg->memory.ptr + offset; b->data = (uint8_t*) seg->memory.ptr + offset;
b->pool = i->pool; b->pool = i->pool;

View file

@ -26,6 +26,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <pulsecore/llist.h> #include <pulsecore/llist.h>
#include <pulsecore/refcnt.h>
/* A pa_memblock is a reference counted memory block. PulseAudio /* A pa_memblock is a reference counted memory block. PulseAudio
* passed references to pa_memblocks around instead of copying * passed references to pa_memblocks around instead of copying
@ -56,7 +57,7 @@ typedef void (*pa_memexport_revoke_cb_t)(pa_memexport *e, uint32_t block_id, voi
struct pa_memblock { struct pa_memblock {
pa_memblock_type_t type; pa_memblock_type_t type;
int read_only; /* boolean */ int read_only; /* boolean */
unsigned ref; /* the reference counter */ PA_REFCNT_DECLARE; /* the reference counter */
size_t length; size_t length;
void *data; void *data;
pa_mempool *pool; pa_mempool *pool;

View file

@ -38,9 +38,11 @@ void pa_memchunk_make_writable(pa_memchunk *c, size_t min) {
assert(c); assert(c);
assert(c->memblock); assert(c->memblock);
assert(c->memblock->ref >= 1); assert(PA_REFCNT_VALUE(c->memblock) > 0);
if (c->memblock->ref == 1 && !c->memblock->read_only && c->memblock->length >= c->index+min) if (PA_REFCNT_VALUE(c->memblock) == 1 &&
!c->memblock->read_only &&
c->memblock->length >= c->index+min)
return; return;
l = c->length; l = c->length;