void queue_foreach(struct queue *queue, queue_foreach_func_t function, void *user_data) { struct queue_entry *entry; if (!queue || !function) return; entry = queue->head; if (!entry) return; queue_ref(queue); while (entry && queue->head && queue->ref_count > 1) { struct queue_entry *next; queue_entry_ref(entry); function(entry->data, user_data); next = entry->next; queue_entry_unref(entry); entry = next; } queue_unref(queue); }
void queue_foreach(struct queue *queue, queue_foreach_func_t function, void *user_data) { struct queue_entry *entry; if (!queue || !function) return; entry = queue->head; if (!entry) return; queue_ref(queue); while (entry && queue->ref_count > 1) { struct queue_entry *tmp = entry; entry = tmp->next; function(tmp->data, user_data); if (!queue_find_entry(queue, entry)) break; } queue_unref(queue); }
struct queue *queue_new(void) { struct queue *queue; queue = new0(struct queue, 1); queue->head = NULL; queue->tail = NULL; queue->entries = 0; return queue_ref(queue); }