line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
// read "rinq" as "ring-queue" |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
struct rinq { |
5
|
|
|
|
|
|
|
struct rinq *next; |
6
|
|
|
|
|
|
|
struct rinq *prev; |
7
|
|
|
|
|
|
|
void *ref; |
8
|
|
|
|
|
|
|
}; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#define RINQ_IS_UNINIT(x_) ((x_)->next == NULL && (x_)->prev == NULL) |
11
|
|
|
|
|
|
|
#define RINQ_IS_DETACHED(x_) ((x_)->next == (x_)) |
12
|
|
|
|
|
|
|
#define RINQ_IS_ATTACHED(x_) ((x_)->next != (x_)) |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#define RINQ_NEW(x_,ref_) do { \ |
15
|
|
|
|
|
|
|
x_ = (struct rinq *)malloc(sizeof(struct rinq)); \ |
16
|
|
|
|
|
|
|
x_->next = x_->prev = x_; \ |
17
|
|
|
|
|
|
|
x_->ref = ref_; \ |
18
|
|
|
|
|
|
|
} while(0) |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
#define RINQ_DETACH(x_) do { \ |
21
|
|
|
|
|
|
|
(x_)->next->prev = (x_)->prev; \ |
22
|
|
|
|
|
|
|
(x_)->prev->next = (x_)->next; \ |
23
|
|
|
|
|
|
|
(x_)->next = (x_)->prev = (x_); \ |
24
|
|
|
|
|
|
|
} while(0) |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
// INLINE_UNLESS_DEBUG |
27
|
|
|
|
|
|
|
// static void |
28
|
|
|
|
|
|
|
// rinq_unshift(struct rinq **head, void *ref) |
29
|
|
|
|
|
|
|
// { |
30
|
|
|
|
|
|
|
// struct rinq *x; |
31
|
|
|
|
|
|
|
// RINQ_NEW(x,ref); |
32
|
|
|
|
|
|
|
// |
33
|
|
|
|
|
|
|
// if ((*head) != NULL) { |
34
|
|
|
|
|
|
|
// x->next = (*head)->next; |
35
|
|
|
|
|
|
|
// x->prev = (*head); |
36
|
|
|
|
|
|
|
// x->next->prev = x->prev->next = x; |
37
|
|
|
|
|
|
|
// } |
38
|
|
|
|
|
|
|
// (*head) = x; |
39
|
|
|
|
|
|
|
// } |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
INLINE_UNLESS_DEBUG |
42
|
|
|
|
|
|
|
static void |
43
|
264
|
|
|
|
|
|
rinq_push (struct rinq **head, void *ref) |
44
|
|
|
|
|
|
|
{ |
45
|
|
|
|
|
|
|
struct rinq *x; |
46
|
264
|
|
|
|
|
|
RINQ_NEW(x,ref); |
47
|
|
|
|
|
|
|
|
48
|
264
|
100
|
|
|
|
|
if ((*head) == NULL) { |
49
|
233
|
|
|
|
|
|
(*head) = x; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
31
|
|
|
|
|
|
x->next = (*head); |
53
|
31
|
|
|
|
|
|
x->prev = (*head)->prev; |
54
|
31
|
|
|
|
|
|
x->next->prev = x->prev->next = x; |
55
|
|
|
|
|
|
|
} |
56
|
264
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
// remove element from tail of rinq |
59
|
|
|
|
|
|
|
// not actually used |
60
|
|
|
|
|
|
|
// INLINE_UNLESS_DEBUG |
61
|
|
|
|
|
|
|
// static void * |
62
|
|
|
|
|
|
|
// rinq_pop (struct rinq **head) { |
63
|
|
|
|
|
|
|
// void *ref; |
64
|
|
|
|
|
|
|
// struct rinq *x; |
65
|
|
|
|
|
|
|
// |
66
|
|
|
|
|
|
|
// if ((*head) == NULL) return NULL; |
67
|
|
|
|
|
|
|
// |
68
|
|
|
|
|
|
|
// if (RINQ_IS_DETACHED((*head))) { |
69
|
|
|
|
|
|
|
// x = (*head); |
70
|
|
|
|
|
|
|
// (*head) = NULL; |
71
|
|
|
|
|
|
|
// } |
72
|
|
|
|
|
|
|
// else { |
73
|
|
|
|
|
|
|
// x = (*head)->prev; |
74
|
|
|
|
|
|
|
// RINQ_DETACH(x); |
75
|
|
|
|
|
|
|
// } |
76
|
|
|
|
|
|
|
// |
77
|
|
|
|
|
|
|
// ref = x->ref; |
78
|
|
|
|
|
|
|
// free(x); |
79
|
|
|
|
|
|
|
// return ref; |
80
|
|
|
|
|
|
|
// } |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
// remove element from head of rinq |
83
|
|
|
|
|
|
|
INLINE_UNLESS_DEBUG |
84
|
|
|
|
|
|
|
static void * |
85
|
264
|
|
|
|
|
|
rinq_shift (struct rinq **head) { |
86
|
|
|
|
|
|
|
void *ref; |
87
|
|
|
|
|
|
|
struct rinq *x; |
88
|
|
|
|
|
|
|
|
89
|
264
|
50
|
|
|
|
|
if ((*head) == NULL) return NULL; |
90
|
|
|
|
|
|
|
|
91
|
264
|
100
|
|
|
|
|
if (RINQ_IS_DETACHED((*head))) { |
92
|
233
|
|
|
|
|
|
x = (*head); |
93
|
233
|
|
|
|
|
|
(*head) = NULL; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
else { |
96
|
31
|
|
|
|
|
|
x = (*head); |
97
|
31
|
|
|
|
|
|
(*head) = (*head)->next; |
98
|
31
|
|
|
|
|
|
RINQ_DETACH(x); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
264
|
|
|
|
|
|
ref = x->ref; |
102
|
264
|
|
|
|
|
|
free(x); |
103
|
264
|
|
|
|
|
|
return ref; |
104
|
|
|
|
|
|
|
} |