summaryrefslogtreecommitdiff
path: root/usr.sbin/unbound/dnstap/dtstream.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/unbound/dnstap/dtstream.c')
-rw-r--r--usr.sbin/unbound/dnstap/dtstream.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/usr.sbin/unbound/dnstap/dtstream.c b/usr.sbin/unbound/dnstap/dtstream.c
index f1ace3c3402..a1dd9703ea9 100644
--- a/usr.sbin/unbound/dnstap/dtstream.c
+++ b/usr.sbin/unbound/dnstap/dtstream.c
@@ -188,9 +188,9 @@ mq_wakeup_cb(void* arg)
/** start timer to wakeup dtio because there is content in the queue */
static void
-dt_msg_queue_start_timer(struct dt_msg_queue* mq)
+dt_msg_queue_start_timer(struct dt_msg_queue* mq, int wakeupnow)
{
- struct timeval tv;
+ struct timeval tv = {0};
/* Start a timer to process messages to be logged.
* If we woke up the dtio thread for every message, the wakeup
* messages take up too much processing power. If the queue
@@ -204,19 +204,26 @@ dt_msg_queue_start_timer(struct dt_msg_queue* mq)
/* do not start the timer if a timer already exists, perhaps
* in another worker. So this variable is protected by a lock in
- * dtio */
+ * dtio. */
+
+ /* If we need to wakeupnow, 0 the timer to force the callback. */
lock_basic_lock(&mq->dtio->wakeup_timer_lock);
if(mq->dtio->wakeup_timer_enabled) {
+ if(wakeupnow) {
+ comm_timer_set(mq->wakeup_timer, &tv);
+ }
lock_basic_unlock(&mq->dtio->wakeup_timer_lock);
return;
}
mq->dtio->wakeup_timer_enabled = 1; /* we are going to start one */
- lock_basic_unlock(&mq->dtio->wakeup_timer_lock);
/* start the timer, in mq, in the event base of our worker */
- tv.tv_sec = 1;
- tv.tv_usec = 0;
+ if(!wakeupnow) {
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ }
comm_timer_set(mq->wakeup_timer, &tv);
+ lock_basic_unlock(&mq->dtio->wakeup_timer_lock);
}
void
@@ -251,7 +258,7 @@ dt_msg_queue_submit(struct dt_msg_queue* mq, void* buf, size_t len)
entry->buf = buf;
entry->len = len;
- /* aqcuire lock */
+ /* acquire lock */
lock_basic_lock(&mq->lock);
/* if list was empty, start timer for (eventual) wakeup */
if(mq->first == NULL)
@@ -283,10 +290,8 @@ dt_msg_queue_submit(struct dt_msg_queue* mq, void* buf, size_t len)
/* release lock */
lock_basic_unlock(&mq->lock);
- if(wakeupnow) {
- dtio_wakeup(mq->dtio);
- } else if(wakeupstarttimer) {
- dt_msg_queue_start_timer(mq);
+ if(wakeupnow || wakeupstarttimer) {
+ dt_msg_queue_start_timer(mq, wakeupnow);
}
}
@@ -930,7 +935,7 @@ static int dtio_write_more_of_data(struct dt_io_thread* dtio)
return 1;
}
-/** write more of the current messsage. false if incomplete, true if
+/** write more of the current message. false if incomplete, true if
* the message is done */
static int dtio_write_more(struct dt_io_thread* dtio)
{
@@ -1181,7 +1186,7 @@ static int dtio_read_accept_frame(struct dt_io_thread* dtio)
goto close_connection;
return 1;
} else {
- /* unknow content type */
+ /* unknown content type */
verbose(VERB_ALGO, "dnstap: ACCEPT frame "
"contains unknown content type, "
"closing connection");