diff options
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/backends/alsa.c | 1 | ||||
-rw-r--r-- | Alc/backends/coreaudio.c | 1 | ||||
-rw-r--r-- | Alc/backends/dsound.c | 1 | ||||
-rw-r--r-- | Alc/backends/jack.c | 1 | ||||
-rw-r--r-- | Alc/backends/mmdevapi.c | 1 | ||||
-rw-r--r-- | Alc/backends/opensl.c | 3 | ||||
-rw-r--r-- | Alc/backends/oss.c | 1 | ||||
-rw-r--r-- | Alc/backends/portaudio.c | 1 | ||||
-rw-r--r-- | Alc/backends/winmm.c | 1 | ||||
-rw-r--r-- | Alc/ringbuffer.c (renamed from Alc/alcRing.c) | 25 | ||||
-rw-r--r-- | Alc/ringbuffer.h | 29 |
11 files changed, 42 insertions, 23 deletions
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c index f941ce4b..fb5a4446 100644 --- a/Alc/backends/alsa.c +++ b/Alc/backends/alsa.c @@ -27,6 +27,7 @@ #include "alMain.h" #include "alu.h" #include "alconfig.h" +#include "ringbuffer.h" #include "threads.h" #include "compat.h" diff --git a/Alc/backends/coreaudio.c b/Alc/backends/coreaudio.c index ec926d3d..ba73ab82 100644 --- a/Alc/backends/coreaudio.c +++ b/Alc/backends/coreaudio.c @@ -27,6 +27,7 @@ #include "alMain.h" #include "alu.h" +#include "ringbuffer.h" #include <CoreServices/CoreServices.h> #include <unistd.h> diff --git a/Alc/backends/dsound.c b/Alc/backends/dsound.c index f730dc95..f88a50c1 100644 --- a/Alc/backends/dsound.c +++ b/Alc/backends/dsound.c @@ -34,6 +34,7 @@ #include "alMain.h" #include "alu.h" +#include "ringbuffer.h" #include "threads.h" #include "compat.h" #include "alstring.h" diff --git a/Alc/backends/jack.c b/Alc/backends/jack.c index 4ef9006c..0dc01ae7 100644 --- a/Alc/backends/jack.c +++ b/Alc/backends/jack.c @@ -27,6 +27,7 @@ #include "alMain.h" #include "alu.h" #include "alconfig.h" +#include "ringbuffer.h" #include "threads.h" #include "compat.h" diff --git a/Alc/backends/mmdevapi.c b/Alc/backends/mmdevapi.c index 9afb62f0..ecd7eb5d 100644 --- a/Alc/backends/mmdevapi.c +++ b/Alc/backends/mmdevapi.c @@ -41,6 +41,7 @@ #include "alMain.h" #include "alu.h" +#include "ringbuffer.h" #include "threads.h" #include "compat.h" #include "alstring.h" diff --git a/Alc/backends/opensl.c b/Alc/backends/opensl.c index aa1ff991..4ec003d8 100644 --- a/Alc/backends/opensl.c +++ b/Alc/backends/opensl.c @@ -26,8 +26,9 @@ #include "alMain.h" #include "alu.h" -#include "compat.h" +#include "ringbuffer.h" #include "threads.h" +#include "compat.h" #include "backends/base.h" diff --git a/Alc/backends/oss.c b/Alc/backends/oss.c index 196432e1..2ff7c72b 100644 --- a/Alc/backends/oss.c +++ b/Alc/backends/oss.c @@ -36,6 +36,7 @@ #include "alMain.h" #include "alu.h" #include "alconfig.h" +#include "ringbuffer.h" #include "threads.h" #include "compat.h" diff --git a/Alc/backends/portaudio.c b/Alc/backends/portaudio.c index 0f4672c4..b793486f 100644 --- a/Alc/backends/portaudio.c +++ b/Alc/backends/portaudio.c @@ -27,6 +27,7 @@ #include "alMain.h" #include "alu.h" #include "alconfig.h" +#include "ringbuffer.h" #include "compat.h" #include "backends/base.h" diff --git a/Alc/backends/winmm.c b/Alc/backends/winmm.c index b5b3cdb6..4e4d0c06 100644 --- a/Alc/backends/winmm.c +++ b/Alc/backends/winmm.c @@ -29,6 +29,7 @@ #include "alMain.h" #include "alu.h" +#include "ringbuffer.h" #include "threads.h" #include "backends/base.h" diff --git a/Alc/alcRing.c b/Alc/ringbuffer.c index d72b34f1..63add593 100644 --- a/Alc/alcRing.c +++ b/Alc/ringbuffer.c @@ -23,6 +23,7 @@ #include <string.h> #include <stdlib.h> +#include "ringbuffer.h" #include "alMain.h" #include "threads.h" #include "almalloc.h" @@ -39,7 +40,6 @@ struct ll_ringbuffer { size_t size; size_t size_mask; size_t elem_size; - int mlocked; alignas(16) char buf[]; }; @@ -49,7 +49,7 @@ struct ll_ringbuffer { ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz) { ll_ringbuffer_t *rb; - ALuint power_of_two; + size_t power_of_two; power_of_two = NextPowerOf2(sz); if(power_of_two < sz) @@ -63,32 +63,13 @@ ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz) rb->size = power_of_two; rb->size_mask = rb->size - 1; rb->elem_size = elem_sz; - rb->mlocked = 0; return rb; } /* Free all data associated with the ringbuffer `rb'. */ void ll_ringbuffer_free(ll_ringbuffer_t *rb) { - if(rb) - { -#ifdef USE_MLOCK - if(rb->mlocked) - munlock(rb, sizeof(*rb) + rb->size*rb->elem_size); -#endif /* USE_MLOCK */ - al_free(rb); - } -} - -/* Lock the data block of `rb' using the system call 'mlock'. */ -int ll_ringbuffer_mlock(ll_ringbuffer_t *rb) -{ -#ifdef USE_MLOCK - if(!rb->mlocked && mlock(rb, sizeof(*rb) + rb->size*rb->elem_size)) - return -1; -#endif /* USE_MLOCK */ - rb->mlocked = 1; - return 0; + al_free(rb); } /* Reset the read and write pointers to zero. This is not thread safe. */ diff --git a/Alc/ringbuffer.h b/Alc/ringbuffer.h new file mode 100644 index 00000000..f764c20f --- /dev/null +++ b/Alc/ringbuffer.h @@ -0,0 +1,29 @@ +#ifndef RINGBUFFER_H +#define RINGBUFFER_H + +#include <stddef.h> + + +typedef struct ll_ringbuffer ll_ringbuffer_t; +typedef struct ll_ringbuffer_data { + char *buf; + size_t len; +} ll_ringbuffer_data_t; + +ll_ringbuffer_t *ll_ringbuffer_create(size_t sz, size_t elem_sz); +void ll_ringbuffer_free(ll_ringbuffer_t *rb); +void ll_ringbuffer_reset(ll_ringbuffer_t *rb); + +void ll_ringbuffer_get_read_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t *vec); +void ll_ringbuffer_get_write_vector(const ll_ringbuffer_t *rb, ll_ringbuffer_data_t *vec); + +size_t ll_ringbuffer_read(ll_ringbuffer_t *rb, char *dest, size_t cnt); +size_t ll_ringbuffer_peek(ll_ringbuffer_t *rb, char *dest, size_t cnt); +void ll_ringbuffer_read_advance(ll_ringbuffer_t *rb, size_t cnt); +size_t ll_ringbuffer_read_space(const ll_ringbuffer_t *rb); + +size_t ll_ringbuffer_write(ll_ringbuffer_t *rb, const char *src, size_t cnt); +void ll_ringbuffer_write_advance(ll_ringbuffer_t *rb, size_t cnt); +size_t ll_ringbuffer_write_space(const ll_ringbuffer_t *rb); + +#endif /* RINGBUFFER_H */ |