circbuf.h

来自「《C++嵌入系统编程》实例源代码,对做嵌入式开发有一定的参考作用」· C头文件 代码 · 共 50 行

H
50
字号
/**********************************************************************
 *
 * Filename:    circbuf.h
 * 
 * Description: An easy-to-use circular buffer class.
 *
 * Notes:       
 *
 * 
 * Copyright (c) 1998 by Michael Barr.  This software is placed into
 * the public domain and may be used for any purpose.  However, this
 * notice must not be changed or removed and no warranty is either
 * expressed or implied by its publication or distribution.
 **********************************************************************/

#ifndef _CIRCBUF_H
#define _CIRCBUF_H


#include "adeos.h"

typedef unsigned char item;

class CircBuf
{
    public:

        CircBuf(int nItems);
        ~CircBuf();

        void  add(item);
        item  remove();
        void  flush()     { head = tail = count = 0; }
                                                     
        int   isEmpty()   { return (count == 0);     }
        int   isFull()    { return (count == size);  }

    private:

        item *  array;
        int     size;
        int     head;
        int     tail;
        int     count;
        Mutex   mutex;
};


#endif /* _CIRCBUF_H */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?