/* * Can only run from the output thread. * * NOTE: this returns a reference which the caller must take care to free. */ static LogMessage * log_queue_fifo_pop_head(LogQueue *s, LogPathOptions *path_options) { LogQueueFifo *self = (LogQueueFifo *) s; LogMessageQueueNode *node; LogMessage *msg = NULL; if (self->qoverflow_output_len == 0) { /* slow path, output queue is empty, get some elements from the wait queue */ g_static_mutex_lock(&self->super.lock); iv_list_splice_tail_init(&self->qoverflow_wait, &self->qoverflow_output); self->qoverflow_output_len = self->qoverflow_wait_len; self->qoverflow_wait_len = 0; g_static_mutex_unlock(&self->super.lock); } if (self->qoverflow_output_len > 0) { node = iv_list_entry(self->qoverflow_output.next, LogMessageQueueNode, list); msg = node->msg; path_options->ack_needed = node->ack_needed; self->qoverflow_output_len--; if (!self->super.use_backlog) { iv_list_del(&node->list); log_msg_free_queue_node(node); } else { iv_list_del_init(&node->list); } } else { /* no items either on the wait queue nor the output queue. * * NOTE: the input queues may contain items even in this case, * however we don't touch them here, they'll be migrated to the * wait_queue once the input threads finish their processing (or * the high watermark is reached). Also, they are unlocked, so * no way to touch them safely. */ return NULL; } stats_counter_dec(self->super.stored_messages); if (self->super.use_backlog) { log_msg_ref(msg); iv_list_add_tail(&node->list, &self->qbacklog); self->qbacklog_len++; } return msg; }
void log_tags_dec_counter(LogTagId id) { /* Reader lock because the log_tag_list is not written */ g_static_mutex_lock(&log_tags_lock); if (id < log_tags_num) stats_counter_dec(log_tags_list[id].counter); g_static_mutex_unlock(&log_tags_lock); }
static LogMessage * _pop_head(LogQueue *s, LogPathOptions *path_options) { LogQueueDisk *self = (LogQueueDisk *) s; LogMessage *msg = NULL; msg = NULL; g_static_mutex_lock(&self->super.lock); if (self->pop_head) { msg = self->pop_head(self, path_options); } if (msg != NULL) { stats_counter_dec(self->super.stored_messages); } g_static_mutex_unlock(&self->super.lock); return msg; }