summaryrefslogtreecommitdiffstats
path: root/c/src/exec/libcsupport/include
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1995-08-01 15:32:09 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1995-08-01 15:32:09 +0000
commit4a6e64d2767e6f49c1f3f021fb1c2907298e5a29 (patch)
treeec29192cc23a0c8e9da71bc1366c5b7cee157701 /c/src/exec/libcsupport/include
parentSwitched to events for mp receive server and eliminated the special (diff)
downloadrtems-4a6e64d2767e6f49c1f3f021fb1c2907298e5a29.tar.bz2
moved ringbuf.h to a shared include directory
Diffstat (limited to 'c/src/exec/libcsupport/include')
-rw-r--r--c/src/exec/libcsupport/include/ringbuf.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/c/src/exec/libcsupport/include/ringbuf.h b/c/src/exec/libcsupport/include/ringbuf.h
new file mode 100644
index 0000000000..b2494c1527
--- /dev/null
+++ b/c/src/exec/libcsupport/include/ringbuf.h
@@ -0,0 +1,42 @@
+/*
+ * ringbuf.h
+ *
+ * This file provides simple ring buffer functionality.
+ *
+ * $Id$
+ */
+
+#ifndef __RINGBUF_H__
+#define __RINGBUF_H__
+
+#ifndef RINGBUF_QUEUE_LENGTH
+#define RINGBUF_QUEUE_LENGTH 200
+#endif
+
+typedef struct {
+ char buffer[RINGBUF_QUEUE_LENGTH];
+ int head;
+ int tail;
+} Ring_buffer_t;
+
+#define Ring_buffer_Initialize( _buffer ) \
+ do { \
+ (_buffer)->head = (_buffer)->tail = 0; \
+ } while ( 0 )
+
+#define Ring_buffer_Is_empty( _buffer ) \
+ ( (_buffer)->head == (_buffer)->tail )
+
+#define Ring_buffer_Add_character( _buffer, _ch ) \
+ do { \
+ (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \
+ (_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \
+ } while ( 0 )
+
+#define Ring_buffer_Remove_character( _buffer, _ch ) \
+ do { \
+ (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \
+ (_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \
+ } while ( 0 )
+
+#endif