-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue.c
More file actions
32 lines (29 loc) · 713 Bytes
/
queue.c
File metadata and controls
32 lines (29 loc) · 713 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include "queue.h"
int enqueue(struct Queue * q, funcPtr fp) {
int index = q->rear + 1;
if(index >= MAXTHREADS) {
index = 0;
}
if(index == q->front) {
return QUEUE_FULL;
}
q->rear = q->rear + 1;
q->fp[index] = fp;
return 0;
}
funcPtr dequeue(struct Queue * q) {
int index = q->front + 1;
if(index >= MAXTHREADS) {
index = 0;
}
if(index == q->rear + 1) {
return NULL;
}
q->front = index;
return q->fp[index];
}
int isEmpty(struct Queue * q) {
return q->front == q->rear ? 1 : 0;
}