rinq.c

filter: Statementstmt 100% 27 / 27 Branchbran 83.3% 15 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 93.3% 42 / 45 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« picotls-git/include/picotls.h ↑ Summary
1  
2 // read "rinq" as "ring-queue"
3  
4 #define RINQ_FREELIST_MAX 64
5 static struct rinq *rinq_freelist = NULL;
6 static int rinq_freelist_count = 0;
7  
8 #define RINQ_IS_DETACHED(x_) ((x_)->next == (x_))
9  
10 #define RINQ_NEW(x_,ref_) do { \
11 if (rinq_freelist != NULL) { \
12 x_ = rinq_freelist; \
13 rinq_freelist = rinq_freelist->next; \
14 rinq_freelist_count--; \
15 } else { \
16 x_ = (struct rinq *)malloc(sizeof(struct rinq)); \
17 if (unlikely(!x_)) croak("Out of memory in rinq"); \
18 } \
19 x_->next = x_->prev = x_; \
20 x_->ref = ref_; \
21 } while(0)
22  
23 #define RINQ_FREE(x_) do { \
24 if (rinq_freelist_count < RINQ_FREELIST_MAX) { \
25 (x_)->next = rinq_freelist; \
26 rinq_freelist = (x_); \
27 rinq_freelist_count++; \
28 } else { \
29 free(x_); \
30 } \
31 } while(0)
32  
33 #define RINQ_DETACH(x_) do { \
34 (x_)->next->prev = (x_)->prev; \
35 (x_)->prev->next = (x_)->next; \
36 (x_)->next = (x_)->prev = (x_); \
37 } while(0)
38  
39 INLINE_UNLESS_DEBUG
40 static struct rinq *
41 35060 rinq_push (struct rinq **head, void *ref)
42 {
43 struct rinq *x;
44 35060 ▶ RINQ_NEW(x,ref);
Branch: 2 branches
BranchTrueFalseTotal
RINQ_NEW(x,ref); 34496 564 35060
RINQ_NEW(x,ref); 0 564 564
45  
46 35060 ▶ if ((*head) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ((*head) == NULL) { 34749 311 35060
47 34749 (*head) = x;
48 }
49 else {
50 311 x->next = (*head);
51 311 x->prev = (*head)->prev;
52 311 x->next->prev = x->prev->next = x;
53 }
54 35060 return x;
55 }
56  
57 INLINE_UNLESS_DEBUG
58 static void *
59 34196 rinq_shift (struct rinq **head) {
60 void *ref;
61 struct rinq *x;
62  
63 34196 ▶ if ((*head) == NULL) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if ((*head) == NULL) return NULL; 202 33994 34196
64  
65 33994 ▶ if (RINQ_IS_DETACHED((*head))) {
Branch: 1 branch
BranchTrueFalseTotal
if (RINQ_IS_DETACHED((*head))) { 33929 65 33994
66 33929 x = (*head);
67 33929 (*head) = NULL;
68 }
69 else {
70 65 x = (*head);
71 65 (*head) = (*head)->next;
72 65 RINQ_DETACH(x);
73 }
74  
75 33994 ref = x->ref;
76 33994 ▶ RINQ_FREE(x);
Branch: 1 branch
BranchTrueFalseTotal
RINQ_FREE(x); 33994 0 33994
77 33994 return ref;
78 }
79  
80 INLINE_UNLESS_DEBUG
81 static void
82 774 rinq_remove (struct rinq **head, struct rinq *node)
83 {
84 774 ▶ if (*head == node) {
Branch: 1 branch
BranchTrueFalseTotal
if (*head == node) { 755 19 774
85 755 ▶ if (node->next == node) {
Branch: 1 branch
BranchTrueFalseTotal
if (node->next == node) { 739 16 755
86 739 *head = NULL;
87 } else {
88 16 *head = node->next;
89 }
90 }
91 774 RINQ_DETACH(node);
92 774 ▶ RINQ_FREE(node);
Branch: 1 branch
BranchTrueFalseTotal
RINQ_FREE(node); 774 0 774
93 774 }
« picotls-git/include/picotls.h ↑ Summary