-
Notifications
You must be signed in to change notification settings - Fork 67
/
buffer.c
51 lines (48 loc) · 981 Bytes
/
buffer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include"buffer.h"
struct BufferAll allBuf;
void initBuffer(struct Buffer *buffer,int bufferSize,unsigned char *tmp)
{
buffer->bufferSize=bufferSize;
buffer->data=tmp;
buffer->flag=0;
buffer->free=buffer->bufferSize;
buffer->h=0;
buffer->r=0;
return;
}
int putBuffer(struct Buffer *buffer,unsigned char data)
{
//Ğ´ÈëÊı¾İ
if (buffer->free==0)
{
buffer->flag=1;
return 0;
}
buffer->data[buffer->r]=data;
buffer->r++;
buffer->r%=buffer->bufferSize;
buffer->free--;
//»½ĞÑÈÎÎñ
/*if (buffer->task!=0)
if (buffer->task->flags!=TASK_USING)
runTask(buffer->task);*/
return 1;
}
int getBuffer(struct Buffer *buffer,unsigned char *data)
{
if (buffer->free==buffer->bufferSize)
return 0;
*data=buffer->data[buffer->h];
buffer->h++;
buffer->h%=buffer->bufferSize;
buffer->free++;
return 1;
}
int fullCountBuffer(struct Buffer *buffer)
{
return buffer->bufferSize-buffer->free;
}
int emptyCountBuffer(struct Buffer *buffer)
{
return buffer->free;
}