📄 key_buf_queue.c
字号:
/**
* usdk130
* queue for key message buffer
* by liwei, 2006,09
*algorithm referenced from
*
* C: The Complete Reference, 4th Ed. (Paperback)
* by Herbert Schildt
*/
#include "key_buf_queue.h"
#include "string.h"
//#define KEY_DEBUG
#ifdef KEY_DEBUG
#define keydbg(x...) printf("KEY debug : " x)
#else
#define keydbg(...) do { } while (0)
#endif
INT32U key_value[KEY_MESSAGE_BUF_SIZE]={0};
unsigned int spos = 0;
unsigned int rpos = 0;
unsigned int cnt = 0;
/* Store ints in the queue. */
void qstore( INT32U q )
{
#if 0
if( is_full() ) {
// printf("List Full\n");
return;
}
#endif
key_value[spos] = q;
spos++;
if( spos==KEY_MESSAGE_BUF_SIZE )
spos = 0; /* loop back */
cnt++;
keydbg("qstore key_value[%d] = %x\t, cnt =%d\n", spos, q, cnt);
}
/* Retrieve an element. */
INT32U qretrieve(void)
{
int value;
if( is_empty() ) {
// printf("List empty()\n");
return 0;
}
value = key_value[rpos];
rpos++;
if(rpos == KEY_MESSAGE_BUF_SIZE)
rpos = 0; /* loop back */
cnt--;
keydbg("qretrieve value = %x, rpos = %d\t, cnt =%d\n",value, rpos, cnt);
return value;
}
int is_empty()
{
if ( cnt == 0 ) {
return 1;
}
return 0;
}
int is_full()
{
if (cnt == KEY_MESSAGE_BUF_SIZE ) {
return 1;
}
return 0;
}
INT32U sizeof_key_buf()
{
return cnt;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -