summaryrefslogtreecommitdiffstats
path: root/c/src/exec/libcsupport/include/ringbuf.h
diff options
context:
space:
mode:
Diffstat (limited to 'c/src/exec/libcsupport/include/ringbuf.h')
-rw-r--r--c/src/exec/libcsupport/include/ringbuf.h25
1 files changed, 18 insertions, 7 deletions
diff --git a/c/src/exec/libcsupport/include/ringbuf.h b/c/src/exec/libcsupport/include/ringbuf.h
index b2494c1527..8c80aaf9c8 100644
--- a/c/src/exec/libcsupport/include/ringbuf.h
+++ b/c/src/exec/libcsupport/include/ringbuf.h
@@ -10,13 +10,13 @@
#define __RINGBUF_H__
#ifndef RINGBUF_QUEUE_LENGTH
-#define RINGBUF_QUEUE_LENGTH 200
+#define RINGBUF_QUEUE_LENGTH 128
#endif
typedef struct {
char buffer[RINGBUF_QUEUE_LENGTH];
- int head;
- int tail;
+ volatile int head;
+ volatile int tail;
} Ring_buffer_t;
#define Ring_buffer_Initialize( _buffer ) \
@@ -27,16 +27,27 @@ typedef struct {
#define Ring_buffer_Is_empty( _buffer ) \
( (_buffer)->head == (_buffer)->tail )
+#define Ring_buffer_Is_full( _buffer ) \
+ ( (_buffer)->head == ((_buffer)->tail + 1) % RINGBUF_QUEUE_LENGTH )
+
#define Ring_buffer_Add_character( _buffer, _ch ) \
do { \
- (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \
- (_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \
+ rtems_unsigned32 isrlevel; \
+ \
+ rtems_interrupt_disable( isrlevel ); \
+ (_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \
+ (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \
+ rtems_interrupt_enable( isrlevel ); \
} while ( 0 )
#define Ring_buffer_Remove_character( _buffer, _ch ) \
do { \
- (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \
- (_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \
+ rtems_unsigned32 isrlevel; \
+ \
+ rtems_interrupt_disable( isrlevel ); \
+ (_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \
+ (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \
+ rtems_interrupt_enable( isrlevel ); \
} while ( 0 )
#endif