xref: /aosp_15_r20/external/erofs-utils/include/erofs/workqueue.h (revision 33b1fccf6a0fada2c2875d400ed01119b7676ee5)
1 /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
2 #ifndef __EROFS_WORKQUEUE_H
3 #define __EROFS_WORKQUEUE_H
4 
5 #include "internal.h"
6 
7 struct erofs_workqueue;
8 
9 typedef void *(*erofs_wq_func_t)(struct erofs_workqueue *, void *);
10 
11 struct erofs_work {
12 	struct erofs_work *next;
13 	void (*fn)(struct erofs_work *work, void *tlsp);
14 };
15 
16 struct erofs_workqueue {
17 	struct erofs_work *head, *tail;
18 	pthread_mutex_t lock;
19 	pthread_cond_t cond_empty;
20 	pthread_cond_t cond_full;
21 	pthread_t *workers;
22 	unsigned int nworker;
23 	unsigned int max_jobs;
24 	unsigned int job_count;
25 	bool shutdown;
26 	erofs_wq_func_t on_start, on_exit;
27 };
28 
29 int erofs_alloc_workqueue(struct erofs_workqueue *wq, unsigned int nworker,
30 			  unsigned int max_jobs, erofs_wq_func_t on_start,
31 			  erofs_wq_func_t on_exit);
32 int erofs_queue_work(struct erofs_workqueue *wq, struct erofs_work *work);
33 int erofs_destroy_workqueue(struct erofs_workqueue *wq);
34 #endif
35