Line data Source code
1 : /* 2 : * Copyright (c) 2017 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifdef __cplusplus 6 : extern "C" { 7 : #endif 8 : #include "task_thread_api.h" 9 : #ifdef __cplusplus 10 : } 11 : #endif 12 : 13 4428 : void thread_new_circular_thread(task_thread *head) 14 : { 15 4428 : if (!head) { 16 0 : return; 17 : } 18 : 19 4428 : head->next = head; 20 4428 : head->prev = head; 21 : 22 4428 : return; 23 : } 24 : 25 2758 : boolean thread_circular_thread_empty(task_thread *head) 26 : { 27 2758 : return (head->next == head) ? TRUE : FALSE; 28 : } 29 : 30 10978 : boolean thread_circular_thread_head(task_thread *head, task_thread *node) 31 : { 32 10978 : return (head == node) ? TRUE : FALSE; 33 : } 34 : 35 2269 : boolean thread_node_on_thread(const task_thread *node) 36 : { 37 2269 : return (node->next) ? TRUE : FALSE; 38 : } 39 : 40 4065 : task_thread *thread_circular_top(task_thread *head) 41 : { 42 4065 : if (head->next == head) { 43 3402 : return NULL; 44 : } 45 : 46 663 : return head->next; 47 : } 48 : 49 3597 : void thread_circular_add_top(task_thread *head, task_thread *node) 50 : { 51 3597 : node->next = head->next; 52 3597 : node->prev = head; 53 3597 : head->next = node; 54 3597 : node->next->prev = node; 55 : 56 3597 : return; 57 : } 58 : 59 1165 : void thread_circular_add_bottom(task_thread *head, task_thread *node) 60 : { 61 1165 : thread_circular_add_top(head->prev, node); 62 1165 : } 63 : 64 10978 : task_thread *thread_next_node(task_thread *node) 65 : { 66 10978 : return node->next; 67 : } 68 : 69 1305 : task_thread *thread_circular_thread_next(task_thread *head, task_thread *node) 70 : { 71 1305 : if (!node) { 72 1100 : return (head->next == head) ? NULL : head->next; 73 : } 74 : 75 205 : return (node->next == head) ? NULL : node->next; 76 : } 77 : 78 5833 : void thread_remove(task_thread *node) 79 : { 80 5833 : if (!node->next) { 81 2236 : return; 82 : } 83 : 84 3597 : node->next->prev = node->prev; 85 3597 : node->prev->next = node->next; 86 : 87 3597 : node->next = NULL; 88 3597 : node->prev = NULL; 89 : } 90 : 91 944 : task_thread *thread_circular_dequeue_top(task_thread *head) 92 : { 93 944 : task_thread *current = NULL; 94 : 95 944 : if (head->next == head) { 96 496 : return NULL; 97 : } 98 : 99 448 : current = head->next; 100 448 : thread_remove(current); 101 : 102 448 : return current; 103 : } 104 :