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 47855 rinq_push (struct rinq **head, void *ref)
42 {
43 struct rinq *x;
44 47855 ▶ RINQ_NEW(x,ref);
Branch: 2 branches
BranchTrueFalseTotal
RINQ_NEW(x,ref); 47291 564 47855
RINQ_NEW(x,ref); 0 564 564
45  
46 47855 ▶ if ((*head) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ((*head) == NULL) { 47547 308 47855
47 47547 (*head) = x;
48 }
49 else {
50 308 x->next = (*head);
51 308 x->prev = (*head)->prev;
52 308 x->next->prev = x->prev->next = x;
53 }
54 47855 return x;
55 }
56  
57 INLINE_UNLESS_DEBUG
58 static void *
59 46991 rinq_shift (struct rinq **head) {
60 void *ref;
61 struct rinq *x;
62  
63 46991 ▶ if ((*head) == NULL) return NULL;
Branch: 1 branch
BranchTrueFalseTotal
if ((*head) == NULL) return NULL; 202 46789 46991
64  
65 46789 ▶ if (RINQ_IS_DETACHED((*head))) {
Branch: 1 branch
BranchTrueFalseTotal
if (RINQ_IS_DETACHED((*head))) { 46726 63 46789
66 46726 x = (*head);
67 46726 (*head) = NULL;
68 }
69 else {
70 63 x = (*head);
71 63 (*head) = (*head)->next;
72 63 RINQ_DETACH(x);
73 }
74  
75 46789 ref = x->ref;
76 46789 ▶ RINQ_FREE(x);
Branch: 1 branch
BranchTrueFalseTotal
RINQ_FREE(x); 46789 0 46789
77 46789 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