| 68 | } |
| 69 | |
| 70 | void queue_free(QUEUE *que, QUEUE_FREE_FN free_fn) |
| 71 | { |
| 72 | QUEUE_ITEM *qi; |
| 73 | int status; |
| 74 | |
| 75 | if (que == NULL) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | if (que->check_owner && thread_self() != que->owner) { |
| 80 | msg_error("%s: cur tid(%lu) != owner(%lu)!", __FUNCTION__, |
| 81 | thread_self(), que->owner); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | que->quit = 1; |
| 86 | status = pthread_mutex_lock(&que->lock); |
| 87 | if (status != 0) { |
| 88 | msg_error("%s: lock error(%s)", __FUNCTION__, last_serror()); |
| 89 | } |
| 90 | |
| 91 | while (1) { |
| 92 | qi = que->first; |
| 93 | if (qi == NULL) { |
| 94 | break; |
| 95 | } |
| 96 | que->first = qi->next; |
| 97 | if (free_fn != NULL) { |
| 98 | free_fn(qi->data); |
| 99 | } |
| 100 | free(qi); |
| 101 | } |
| 102 | |
| 103 | status = pthread_mutex_unlock(&que->lock); |
| 104 | if (status != 0) { |
| 105 | msg_error("%s: lock error(%s)", __FUNCTION__, last_serror()); |
| 106 | } |
| 107 | |
| 108 | pthread_mutex_destroy(&que->lock); |
| 109 | pthread_cond_destroy(&que->cond); |
| 110 | free(que); |
| 111 | } |
| 112 | |
| 113 | static int queue_wait(QUEUE *que, const struct timespec *ptimeo) |
| 114 | { |
nothing calls this directly
no test coverage detected
searching dependent graphs…