-
Notifications
You must be signed in to change notification settings - Fork 1
/
queue.c
50 lines (31 loc) · 1 KB
/
queue.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
#include "defines.h"
#include "queue.h"
#include "frame.h"
#include "uwmodem.h"
#if DEBUG
#include <stdio.h>
#endif
/* Woohoo! Constant time Queue array implementation */
int appendFrame( Frame *frame, Frame* queue, int* head, int* tail){
#if DEBUG
printf("queue.c: appendFrame() -> 0x%2X 0x%2X 0x%2X 0x%2X \n", frame->data[0], frame->data[1], frame->data[2], frame->data[3]);
printf("queue.c: appendFrame() -> %c %c %c %c \n", frame->data[0], frame->data[1], frame->data[2], frame->data[3]);
#endif
if( (*tail) >= (*head) + STACK_SIZE )
return 0;
deepCopy(frame, &(queue[*tail]));
/* restrict within STACK_SIZE */
(*tail) = (*tail + 1) % STACK_SIZE;
return 1;
}
int firstFrame(Frame * result, Frame *queue, int* head, int* tail){
if (*tail == *head){
return 0;
}
deepCopy(&(queue[*head]), result);
(*head)++;
(*head) %= STACK_SIZE;
}
int getSize(int head, int tail){
return (tail+STACK_SIZE-head) % STACK_SIZE;
}