#include <pthread.h>
#include <stdbool.h>
-struct thread_pool__job_info {
+struct thread_pool__job {
kvm_thread_callback_fn_t callback;
struct kvm *kvm;
void *data;
static pthread_t *threads;
static long threadcount;
-static struct thread_pool__job_info *thread_pool__job_info_pop(void)
+static struct thread_pool__job *thread_pool__job_pop(void)
{
- struct thread_pool__job_info *job;
+ struct thread_pool__job *job;
if (list_empty(&head))
return NULL;
- job = list_first_entry(&head, struct thread_pool__job_info, queue);
+ job = list_first_entry(&head, struct thread_pool__job, queue);
list_del(&job->queue);
return job;
}
-static void thread_pool__job_info_push(struct thread_pool__job_info *job)
+static void thread_pool__job_push(struct thread_pool__job *job)
{
list_add_tail(&job->queue, &head);
}
-static struct thread_pool__job_info *thread_pool__job_info_pop_locked(void)
+static struct thread_pool__job *thread_pool__job_pop_locked(void)
{
- struct thread_pool__job_info *job;
+ struct thread_pool__job *job;
mutex_lock(&job_mutex);
- job = thread_pool__job_info_pop();
+ job = thread_pool__job_pop();
mutex_unlock(&job_mutex);
return job;
}
-static void thread_pool__job_info_push_locked(struct thread_pool__job_info *job)
+static void thread_pool__job_push_locked(struct thread_pool__job *job)
{
mutex_lock(&job_mutex);
- thread_pool__job_info_push(job);
+ thread_pool__job_push(job);
mutex_unlock(&job_mutex);
}
-static void thread_pool__handle_job(struct thread_pool__job_info *job)
+static void thread_pool__handle_job(struct thread_pool__job *job)
{
while (job) {
job->callback(job->kvm, job->data);
if (--job->signalcount > 0)
/* If the job was signaled again while we were working */
- thread_pool__job_info_push_locked(job);
+ thread_pool__job_push_locked(job);
mutex_unlock(&job->mutex);
- job = thread_pool__job_info_pop_locked();
+ job = thread_pool__job_pop_locked();
}
}
pthread_cleanup_push(thread_pool__threadfunc_cleanup, NULL);
for (;;) {
- struct thread_pool__job_info *curjob;
+ struct thread_pool__job *curjob;
mutex_lock(&job_mutex);
pthread_cond_wait(&job_cond, &job_mutex);
- curjob = thread_pool__job_info_pop();
+ curjob = thread_pool__job_pop();
mutex_unlock(&job_mutex);
if (curjob)
return i;
}
-void *thread_pool__add_jobtype(struct kvm *kvm,
+void *thread_pool__add_job(struct kvm *kvm,
kvm_thread_callback_fn_t callback, void *data)
{
- struct thread_pool__job_info *job = calloc(1, sizeof(*job));
+ struct thread_pool__job *job = calloc(1, sizeof(*job));
- *job = (struct thread_pool__job_info) {
+ *job = (struct thread_pool__job) {
.kvm = kvm,
.data = data,
.callback = callback,
return job;
}
-void thread_pool__signal_work(void *job)
+void thread_pool__do_job(void *job)
{
- struct thread_pool__job_info *jobinfo = job;
+ struct thread_pool__job *jobinfo = job;
if (jobinfo == NULL)
return;
mutex_lock(&jobinfo->mutex);
if (jobinfo->signalcount++ == 0)
- thread_pool__job_info_push_locked(job);
+ thread_pool__job_push_locked(job);
mutex_unlock(&jobinfo->mutex);
pthread_cond_signal(&job_cond);
void virtio_console__inject_interrupt(struct kvm *self)
{
- thread_pool__signal_work(console_device.jobs[VIRTIO_CONSOLE_RX_QUEUE]);
+ thread_pool__do_job(console_device.jobs[VIRTIO_CONSOLE_RX_QUEUE]);
}
static bool virtio_console_pci_io_device_specific_in(void *data, unsigned long offset, int size, uint32_t count)
if (console_device.queue_selector == VIRTIO_CONSOLE_TX_QUEUE)
console_device.jobs[console_device.queue_selector] =
- thread_pool__add_jobtype(self, virtio_console_handle_callback, queue);
+ thread_pool__add_job(self, virtio_console_handle_callback, queue);
else if (console_device.queue_selector == VIRTIO_CONSOLE_RX_QUEUE)
console_device.jobs[console_device.queue_selector] =
- thread_pool__add_jobtype(self, virtio_console__inject_interrupt_callback, queue);
+ thread_pool__add_job(self, virtio_console__inject_interrupt_callback, queue);
break;
}
case VIRTIO_PCI_QUEUE_NOTIFY: {
uint16_t queue_index;
queue_index = ioport__read16(data);
- thread_pool__signal_work(console_device.jobs[queue_index]);
+ thread_pool__do_job(console_device.jobs[queue_index]);
break;
}
case VIRTIO_PCI_STATUS: