mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-13 13:29:58 -05:00
Merge HUGE set of changes temporarily into a branch, to allow me to move them from one machine to another (lock-free and stuff)
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1469 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
6aeec56708
commit
00da37f2c4
72 changed files with 4389 additions and 1767 deletions
110
src/tests/asyncmsgq-test.c
Normal file
110
src/tests/asyncmsgq-test.c
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
/* $Id$ */
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <pulse/util.h>
|
||||
#include <pulse/xmalloc.h>
|
||||
#include <pulsecore/asyncmsgq.h>
|
||||
#include <pulsecore/thread.h>
|
||||
#include <pulsecore/log.h>
|
||||
#include <pulsecore/core-util.h>
|
||||
#include <pulsecore/macro.h>
|
||||
|
||||
enum {
|
||||
OPERATION_A,
|
||||
OPERATION_B,
|
||||
OPERATION_C,
|
||||
QUIT
|
||||
};
|
||||
|
||||
static void the_thread(void *_q) {
|
||||
pa_asyncmsgq *q = _q;
|
||||
int quit = 0;
|
||||
|
||||
do {
|
||||
int code = 0;
|
||||
|
||||
pa_assert_se(pa_asyncmsgq_get(q, NULL, &code, NULL, 1) == 0);
|
||||
|
||||
switch (code) {
|
||||
|
||||
case OPERATION_A:
|
||||
printf("Operation A\n");
|
||||
break;
|
||||
|
||||
case OPERATION_B:
|
||||
printf("Operation B\n");
|
||||
break;
|
||||
|
||||
case OPERATION_C:
|
||||
printf("Operation C\n");
|
||||
break;
|
||||
|
||||
case QUIT:
|
||||
printf("quit\n");
|
||||
quit = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
pa_asyncmsgq_done(q);
|
||||
|
||||
} while (!quit);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
pa_asyncmsgq *q;
|
||||
pa_thread *t;
|
||||
|
||||
pa_assert_se(q = pa_asyncmsgq_new(0));
|
||||
|
||||
pa_assert_se(t = pa_thread_new(the_thread, q));
|
||||
|
||||
printf("Operation A post\n");
|
||||
pa_asyncmsgq_post(q, NULL, OPERATION_A, NULL, NULL, NULL);
|
||||
|
||||
pa_thread_yield();
|
||||
|
||||
printf("Operation B post\n");
|
||||
pa_asyncmsgq_post(q, NULL, OPERATION_B, NULL, NULL, NULL);
|
||||
|
||||
pa_thread_yield();
|
||||
|
||||
printf("Operation C send\n");
|
||||
pa_asyncmsgq_send(q, NULL, OPERATION_C, NULL);
|
||||
|
||||
pa_thread_yield();
|
||||
|
||||
printf("Quit post\n");
|
||||
pa_asyncmsgq_post(q, NULL, QUIT, NULL, NULL, NULL);
|
||||
|
||||
pa_thread_free(t);
|
||||
|
||||
pa_asyncmsgq_free(q);
|
||||
|
||||
return 0;
|
||||
}
|
||||
87
src/tests/asyncq-test.c
Normal file
87
src/tests/asyncq-test.c
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/* $Id$ */
|
||||
|
||||
/***
|
||||
This file is part of PulseAudio.
|
||||
|
||||
PulseAudio is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published
|
||||
by the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
PulseAudio is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with PulseAudio; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
USA.
|
||||
***/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <pulse/util.h>
|
||||
#include <pulse/xmalloc.h>
|
||||
#include <pulsecore/asyncq.h>
|
||||
#include <pulsecore/thread.h>
|
||||
#include <pulsecore/log.h>
|
||||
#include <pulsecore/core-util.h>
|
||||
#include <pulsecore/macro.h>
|
||||
|
||||
static void producer(void *_q) {
|
||||
pa_asyncq *q = _q;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 1000; i++) {
|
||||
pa_asyncq_push(q, (void*) (i+1), 1);
|
||||
printf("pushed %i\n", i);
|
||||
}
|
||||
|
||||
pa_asyncq_push(q, (void*) -1, 1);
|
||||
printf("pushed end\n");
|
||||
}
|
||||
|
||||
static void consumer(void *_q) {
|
||||
pa_asyncq *q = _q;
|
||||
void *p;
|
||||
int i;
|
||||
|
||||
sleep(1);
|
||||
|
||||
for (i = 0;; i++) {
|
||||
p = pa_asyncq_pop(q, 1);
|
||||
|
||||
if (p == (void*) -1)
|
||||
break;
|
||||
|
||||
pa_assert(p == (void *) (i+1));
|
||||
|
||||
printf("popped %i\n", i);
|
||||
}
|
||||
|
||||
printf("popped end\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
pa_asyncq *q;
|
||||
pa_thread *t1, *t2;
|
||||
|
||||
pa_assert_se(q = pa_asyncq_new(0));
|
||||
|
||||
pa_assert_se(t1 = pa_thread_new(producer, q));
|
||||
pa_assert_se(t2 = pa_thread_new(consumer, q));
|
||||
|
||||
pa_thread_free(t1);
|
||||
pa_thread_free(t2);
|
||||
|
||||
pa_asyncq_free(q, NULL);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -59,24 +59,29 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
|
|||
c.index = c.length = 0;
|
||||
}
|
||||
|
||||
assert(c.index < c.memblock->length);
|
||||
assert(c.index < pa_memblock_get_length(c.memblock));
|
||||
|
||||
l = c.memblock->length - c.index;
|
||||
l = pa_memblock_get_length(c.memblock) - c.index;
|
||||
|
||||
l = l <= 1 ? l : rand() % (l-1) +1 ;
|
||||
|
||||
if ((r = read(STDIN_FILENO, (uint8_t*) c.memblock->data + c.index, l)) <= 0) {
|
||||
p = pa_memblock_acquire(c.memblock);
|
||||
|
||||
if ((r = read(STDIN_FILENO, (uint8_t*) p + c.index, l)) <= 0) {
|
||||
pa_memblock_release(c.memblock);
|
||||
fprintf(stderr, "read() failed: %s\n", r < 0 ? strerror(errno) : "EOF");
|
||||
break;
|
||||
}
|
||||
|
||||
pa_memblock_release(c.memblock);
|
||||
|
||||
c.length = r;
|
||||
pa_mcalign_push(a, &c);
|
||||
fprintf(stderr, "Read %ld bytes\n", (long)r);
|
||||
|
||||
c.index += r;
|
||||
|
||||
if (c.index >= c.memblock->length) {
|
||||
if (c.index >= pa_memblock_get_length(c.memblock)) {
|
||||
pa_memblock_unref(c.memblock);
|
||||
pa_memchunk_reset(&c);
|
||||
}
|
||||
|
|
@ -87,7 +92,9 @@ int main(PA_GCC_UNUSED int argc, PA_GCC_UNUSED char *argv[]) {
|
|||
if (pa_mcalign_pop(a, &t) < 0)
|
||||
break;
|
||||
|
||||
pa_loop_write(STDOUT_FILENO, (uint8_t*) t.memblock->data + t.index, t.length, NULL);
|
||||
p = pa_memblock_acquire(t.memblock);
|
||||
pa_loop_write(STDOUT_FILENO, (uint8_t*) p + t.index, t.length, NULL);
|
||||
pa_memblock_release(t.memblock);
|
||||
fprintf(stderr, "Wrote %lu bytes.\n", (unsigned long) t.length);
|
||||
|
||||
pa_memblock_unref(t.memblock);
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ int main(int argc, char *argv[]) {
|
|||
pa_memblock* blocks[5];
|
||||
uint32_t id, shm_id;
|
||||
size_t offset, size;
|
||||
char *x;
|
||||
|
||||
const char txt[] = "This is a test!";
|
||||
|
||||
|
|
@ -90,10 +91,17 @@ int main(int argc, char *argv[]) {
|
|||
assert(pool_a && pool_b && pool_c);
|
||||
|
||||
blocks[0] = pa_memblock_new_fixed(pool_a, (void*) txt, sizeof(txt), 1);
|
||||
|
||||
blocks[1] = pa_memblock_new(pool_a, sizeof(txt));
|
||||
snprintf(blocks[1]->data, blocks[1]->length, "%s", txt);
|
||||
x = pa_memblock_acquire(blocks[1]);
|
||||
snprintf(x, pa_memblock_get_length(blocks[1]), "%s", txt);
|
||||
pa_memblock_release(blocks[1]);
|
||||
|
||||
blocks[2] = pa_memblock_new_pool(pool_a, sizeof(txt));
|
||||
snprintf(blocks[2]->data, blocks[2]->length, "%s", txt);
|
||||
x = pa_memblock_acquire(blocks[2]);
|
||||
snprintf(x, pa_memblock_get_length(blocks[2]), "%s", txt);
|
||||
pa_memblock_release(blocks[1]);
|
||||
|
||||
blocks[3] = pa_memblock_new_malloced(pool_a, pa_xstrdup(txt), sizeof(txt));
|
||||
blocks[4] = NULL;
|
||||
|
||||
|
|
@ -130,14 +138,18 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
mb_c = pa_memimport_get(import_c, id, shm_id, offset, size);
|
||||
assert(mb_c);
|
||||
printf("1 data=%s\n", (char*) mb_c->data);
|
||||
x = pa_memblock_acquire(mb_c);
|
||||
printf("1 data=%s\n", x);
|
||||
pa_memblock_release(mb_c);
|
||||
|
||||
print_stats(pool_a, "A");
|
||||
print_stats(pool_b, "B");
|
||||
print_stats(pool_c, "C");
|
||||
|
||||
pa_memexport_free(export_b);
|
||||
printf("2 data=%s\n", (char*) mb_c->data);
|
||||
x = pa_memblock_acquire(mb_c);
|
||||
printf("2 data=%s\n", x);
|
||||
pa_memblock_release(mb_c);
|
||||
pa_memblock_unref(mb_c);
|
||||
|
||||
pa_memimport_free(import_b);
|
||||
|
|
|
|||
|
|
@ -131,8 +131,10 @@ int main(int argc, char *argv[]) {
|
|||
if (pa_memblockq_peek(bq, &out) < 0)
|
||||
break;
|
||||
|
||||
for (e = (char*) out.memblock->data + out.index, n = 0; n < out.length; n++)
|
||||
p = pa_memblock_acquire(out.memblock);
|
||||
for (e = (char*) p + out.index, n = 0; n < out.length; n++)
|
||||
printf("%c", *e);
|
||||
pa_memblock_release(out.memblock);
|
||||
|
||||
pa_memblock_unref(out.memblock);
|
||||
pa_memblockq_drop(bq, &out, out.length);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue