Mercurial > audlegacy-plugins
comparison src/neon/rb.h @ 2151:9a9f406374c6
- Update ring buffer code to newer version
author | Ralf Ertzinger <ralf@skytale.net> |
---|---|
date | Sun, 04 Nov 2007 14:04:37 +0100 |
parents | dc83901850df |
children | b73ea297d197 |
comparison
equal
deleted
inserted
replaced
2150:04421592e6a3 | 2151:9a9f406374c6 |
---|---|
15 */ | 15 */ |
16 | 16 |
17 #ifndef _RB_H | 17 #ifndef _RB_H |
18 #define _RB_H | 18 #define _RB_H |
19 | 19 |
20 #ifdef _RB_USE_GLIB | |
21 #include <glib.h> | |
22 | |
23 typedef GMutex rb_mutex_t; | |
24 #define _RB_LOCK(L) g_mutex_lock(L) | |
25 #define _RB_UNLOCK(L) g_mutex_unlock(L) | |
26 | |
27 #else | |
20 #include <pthread.h> | 28 #include <pthread.h> |
29 | |
30 typedef pthread_mutex_t rb_mutex_t; | |
31 #define _RB_LOCK(L) pthread_mutex_lock(L) | |
32 #define _RB_UNLOCK(L) pthread_mutex_unlock(L) | |
33 #endif | |
34 | |
21 #include <stdlib.h> | 35 #include <stdlib.h> |
22 | 36 |
23 #ifdef RB_DEBUG | 37 #ifdef RB_DEBUG |
24 #define ASSERT_RB(buf) _assert_rb(buf) | 38 #define ASSERT_RB(buf) _assert_rb(buf) |
25 #else | 39 #else |
26 #define ASSERT_RB(buf) | 40 #define ASSERT_RB(buf) |
27 #endif | 41 #endif |
28 | 42 |
29 struct ringbuf { | 43 struct ringbuf { |
30 pthread_mutex_t lock; | 44 rb_mutex_t* lock; |
45 char _free_lock; | |
31 char* buf; | 46 char* buf; |
32 char* end; | 47 char* end; |
33 char* wp; | 48 char* wp; |
34 char* rp; | 49 char* rp; |
35 unsigned int free; | 50 unsigned int free; |
36 unsigned int used; | 51 unsigned int used; |
37 unsigned int size; | 52 unsigned int size; |
38 }; | 53 }; |
39 | 54 |
40 int init_rb(struct ringbuf* rb, unsigned int size); | 55 int init_rb(struct ringbuf* rb, unsigned int size); |
56 int init_rb_with_lock(struct ringbuf* rb, unsigned int size, rb_mutex_t* lock); | |
41 int write_rb(struct ringbuf* rb, void* buf, unsigned int size); | 57 int write_rb(struct ringbuf* rb, void* buf, unsigned int size); |
42 int read_rb(struct ringbuf* rb, void* buf, unsigned int size); | 58 int read_rb(struct ringbuf* rb, void* buf, unsigned int size); |
43 int read_rb_locked(struct ringbuf* rb, void* buf, unsigned int size); | 59 int read_rb_locked(struct ringbuf* rb, void* buf, unsigned int size); |
44 void reset_rb(struct ringbuf* rb); | 60 void reset_rb(struct ringbuf* rb); |
45 unsigned int free_rb(struct ringbuf* rb); | 61 unsigned int free_rb(struct ringbuf* rb); |
62 unsigned int free_rb_locked(struct ringbuf* rb); | |
46 unsigned int used_rb(struct ringbuf* rb); | 63 unsigned int used_rb(struct ringbuf* rb); |
47 void destroy_rb(struct ringbuf* rb); | 64 void destroy_rb(struct ringbuf* rb); |
48 | 65 |
49 #endif | 66 #endif |