void nn_worker_execute (struct nn_worker *self, struct nn_worker_task *task) { nn_mutex_lock (&self->sync); nn_queue_push (&self->tasks, &task->item); nn_efd_signal (&self->efd); nn_mutex_unlock (&self->sync); }
void nn_worker_term (struct nn_worker *self) { /* Ask worker thread to terminate. */ nn_mutex_lock (&self->sync); nn_queue_push (&self->tasks, &self->stop); nn_efd_signal (&self->efd); nn_mutex_unlock (&self->sync); /* Wait till worker thread terminates. */ nn_thread_term (&self->thread); /* Clean up. */ nn_timerset_term (&self->timerset); nn_poller_term (&self->poller); nn_efd_term (&self->efd); nn_queue_item_term (&self->stop); nn_queue_term (&self->tasks); nn_mutex_term (&self->sync); }