source: rtems/cpukit/libcsupport/include/ringbuf.h @ 7f6a24ab

4.104.114.84.95
Last change on this file since 7f6a24ab was 4a6e64d, checked in by Joel Sherrill <joel.sherrill@…>, on 08/01/95 at 15:32:09

moved ringbuf.h to a shared include directory

  • Property mode set to 100644
File size: 919 bytes
Line 
1/*
2 *  ringbuf.h
3 *
4 *  This file provides simple ring buffer functionality.
5 *
6 *  $Id$
7 */
8
9#ifndef __RINGBUF_H__
10#define __RINGBUF_H__
11
12#ifndef RINGBUF_QUEUE_LENGTH
13#define RINGBUF_QUEUE_LENGTH 200
14#endif
15
16typedef struct {
17  char buffer[RINGBUF_QUEUE_LENGTH];
18  int  head;
19  int  tail;
20} Ring_buffer_t;
21
22#define Ring_buffer_Initialize( _buffer ) \
23  do { \
24    (_buffer)->head = (_buffer)->tail = 0; \
25  } while ( 0 )
26 
27#define Ring_buffer_Is_empty( _buffer ) \
28   ( (_buffer)->head == (_buffer)->tail )
29
30#define Ring_buffer_Add_character( _buffer, _ch ) \
31  do { \
32    (_buffer)->buffer[ (_buffer)->tail ] = (_ch); \
33    (_buffer)->tail = ((_buffer)->tail+1) % RINGBUF_QUEUE_LENGTH; \
34  } while ( 0 )
35
36#define Ring_buffer_Remove_character( _buffer, _ch ) \
37  do { \
38    (_ch) = (_buffer)->buffer[ (_buffer)->head ]; \
39    (_buffer)->head = ((_buffer)->head+1) % RINGBUF_QUEUE_LENGTH; \
40  } while ( 0 )
41
42#endif
Note: See TracBrowser for help on using the repository browser.