-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcb_pdeque.c
44 lines (38 loc) · 1006 Bytes
/
pcb_pdeque.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
#include "pcb_pdeque.h"
int is_pcb_pdeque_empty(pcb_deque* in_pcb_pdeque) {
if(in_pcb_pdeque == NULL) {
return RTX_ERROR;
}
int i = 0;
for(; i<NUM_PRIORITY; i++) {
if(!is_pcb_deque_empty(&in_pcb_pdeque[i])) {
return FALSE;
}
}
return TRUE;
}
pcb* pcb_deque_highest(pcb_deque* in_pcb_pdeque) {
if(in_pcb_pdeque == NULL) {
// remember, dequing from a NULL queue returns NULL; not an error, per-se
return NULL;
}
int i = 0;
for(; i<NUM_PRIORITY; i++) {
if(!is_pcb_deque_empty(&in_pcb_pdeque[i])) {
return pcb_dequeue(&in_pcb_pdeque[i]);
}
}
return NULL;
}
pcb* pcb_peek_highest(pcb_deque* in_pcb_pdeque) {
if(in_pcb_pdeque == NULL) {
return NULL;
}
int i = 0;
for(; i<NUM_PRIORITY; i++) {
if(!is_pcb_deque_empty(&in_pcb_pdeque[i])) {
return pcb_peek_head(&in_pcb_pdeque[i]);
}
}
return NULL; // nothing found
}