queue.cpp

来自「DOS下采用中断接收数据的串口通讯的例子,很难找到的好东西!」· C++ 代码 · 共 34 行

CPP
34
字号
//
//  QUEUE.CPP
//
//  Source code from:
//
//  Serial Communications: A C++ Developer's Guide, 2nd Edition
//  by Mark Nelson, IDG Books, 1999
//
//  Please see the book for information on usage.
//
// Most of the queue class functions are defined in QUEUE.H as
// inline for speed.  This routine probably won't generate
// inline code with most compilers, and it is not used in the
// ISR, so speed is not as critical.  Thus, it gets defined
// normally.

#include "queue.h"

int Queue::Peek( unsigned char *buf, int count )
{
    unsigned int index = tail_index;
    int total = 0;

    while ( total < count && index != head_index ) {
         *buf++ = buffer[ index++ ];
         if ( index >= QueueSize )
             index = 0;
         total++;
    }
    return total;
}
// ******************** END OF QUEUE.CPP *******************

⌨️ 快捷键说明

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