threadpool.h 863 Bytes
Newer Older
1
2
3
#ifndef KVM__THREADPOOL_H
#define KVM__THREADPOOL_H

4
5
6
7
#include "kvm/mutex.h"

#include <linux/list.h>

8
9
10
11
struct kvm;

typedef void (*kvm_thread_callback_fn_t)(struct kvm *kvm, void *data);

12
13
14
15
16
17
struct thread_pool__job {
	kvm_thread_callback_fn_t	callback;
	struct kvm			*kvm;
	void				*data;

	int				signalcount;
18
	struct mutex			mutex;
19

20
21
22
23
24
25
26
27
28
	struct list_head		queue;
};

static inline void thread_pool__init_job(struct thread_pool__job *job, struct kvm *kvm, kvm_thread_callback_fn_t callback, void *data)
{
	*job = (struct thread_pool__job) {
		.kvm		= kvm,
		.callback	= callback,
		.data		= data,
29
		.mutex		= MUTEX_INITIALIZER,
30
	};
31
	INIT_LIST_HEAD(&job->queue);
32
33
}

34
35
int thread_pool__init(struct kvm *kvm);
int thread_pool__exit(struct kvm *kvm);
36

37
void thread_pool__do_job(struct thread_pool__job *job);
38
void thread_pool__cancel_job(struct thread_pool__job *job);
39
40

#endif