mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-12-27 08:56:52 -05:00
rework memory block management to be thread-safe and mostly lock-free.
pa_memblock is now an opaque structure. Access to its fields is now done through various accessor functions in a thread-safe manner. pa_memblock_acquire() and pa_memblock_release() are now used to access the attached audio data. Why? To allow safe manipulation of the memory pointer maintained by the memory block. Internally _acquire() and _release() maintain a reference counter. Please do not confuse this reference counter whith the one maintained by pa_memblock_ref()/_unref()! As a side effect this patch removes all direct usages of AO_t and replaces it with pa_atomic_xxx based code. This stuff needs some serious testing love. Especially if threads are actively used. git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@1404 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
5ad143b3ab
commit
d210ebbb09
36 changed files with 991 additions and 500 deletions
|
|
@ -113,6 +113,7 @@ static int do_read(struct connection *c) {
|
|||
pa_memchunk chunk;
|
||||
ssize_t r;
|
||||
size_t l;
|
||||
void *p;
|
||||
|
||||
if (!c->sink_input || !(l = pa_memblockq_missing(c->input_memblockq)))
|
||||
return 0;
|
||||
|
|
@ -121,7 +122,7 @@ static int do_read(struct connection *c) {
|
|||
l = c->playback.fragment_size;
|
||||
|
||||
if (c->playback.current_memblock)
|
||||
if (c->playback.current_memblock->length - c->playback.memblock_index < l) {
|
||||
if (pa_memblock_get_length(c->playback.current_memblock) - c->playback.memblock_index < l) {
|
||||
pa_memblock_unref(c->playback.current_memblock);
|
||||
c->playback.current_memblock = NULL;
|
||||
c->playback.memblock_index = 0;
|
||||
|
|
@ -129,15 +130,20 @@ static int do_read(struct connection *c) {
|
|||
|
||||
if (!c->playback.current_memblock) {
|
||||
c->playback.current_memblock = pa_memblock_new(c->protocol->core->mempool, c->playback.fragment_size*2);
|
||||
assert(c->playback.current_memblock && c->playback.current_memblock->length >= l);
|
||||
assert(c->playback.current_memblock);
|
||||
assert(pa_memblock_get_length(c->playback.current_memblock) >= l);
|
||||
c->playback.memblock_index = 0;
|
||||
}
|
||||
|
||||
p = pa_memblock_acquire(c->playback.current_memblock);
|
||||
|
||||
if ((r = pa_iochannel_read(c->io, (uint8_t*) c->playback.current_memblock->data+c->playback.memblock_index, l)) <= 0) {
|
||||
if ((r = pa_iochannel_read(c->io, (uint8_t*) p + c->playback.memblock_index, l)) <= 0) {
|
||||
pa_memblock_release(c->playback.current_memblock);
|
||||
pa_log_debug("read(): %s", r == 0 ? "EOF" : pa_cstrerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
pa_memblock_release(c->playback.current_memblock);
|
||||
chunk.memblock = c->playback.current_memblock;
|
||||
chunk.index = c->playback.memblock_index;
|
||||
chunk.length = r;
|
||||
|
|
@ -156,7 +162,8 @@ static int do_read(struct connection *c) {
|
|||
static int do_write(struct connection *c) {
|
||||
pa_memchunk chunk;
|
||||
ssize_t r;
|
||||
|
||||
void *p;
|
||||
|
||||
if (!c->source_output)
|
||||
return 0;
|
||||
|
||||
|
|
@ -165,12 +172,17 @@ static int do_write(struct connection *c) {
|
|||
return 0;
|
||||
|
||||
assert(chunk.memblock && chunk.length);
|
||||
|
||||
p = pa_memblock_acquire(chunk.memblock);
|
||||
|
||||
if ((r = pa_iochannel_write(c->io, (uint8_t*) chunk.memblock->data+chunk.index, chunk.length)) < 0) {
|
||||
if ((r = pa_iochannel_write(c->io, (uint8_t*) p+chunk.index, chunk.length)) < 0) {
|
||||
pa_memblock_release(chunk.memblock);
|
||||
pa_memblock_unref(chunk.memblock);
|
||||
pa_log("write(): %s", pa_cstrerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
pa_memblock_release(chunk.memblock);
|
||||
|
||||
pa_memblockq_drop(c->output_memblockq, &chunk, r);
|
||||
pa_memblock_unref(chunk.memblock);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue