File: workqueue.h

package info (click to toggle)
erofs-utils 1.8.10-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 1,128 kB
  • sloc: ansic: 20,839; makefile: 164; sh: 33
file content (34 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
#ifndef __EROFS_WORKQUEUE_H
#define __EROFS_WORKQUEUE_H

#include "internal.h"

struct erofs_workqueue;

typedef void *(*erofs_wq_func_t)(struct erofs_workqueue *, void *);

struct erofs_work {
	struct erofs_work *next;
	void (*fn)(struct erofs_work *work, void *tlsp);
};

struct erofs_workqueue {
	struct erofs_work *head, *tail;
	pthread_mutex_t lock;
	pthread_cond_t cond_empty;
	pthread_cond_t cond_full;
	pthread_t *workers;
	unsigned int nworker;
	unsigned int max_jobs;
	unsigned int job_count;
	bool shutdown;
	erofs_wq_func_t on_start, on_exit;
};

int erofs_alloc_workqueue(struct erofs_workqueue *wq, unsigned int nworker,
			  unsigned int max_jobs, erofs_wq_func_t on_start,
			  erofs_wq_func_t on_exit);
int erofs_queue_work(struct erofs_workqueue *wq, struct erofs_work *work);
int erofs_destroy_workqueue(struct erofs_workqueue *wq);
#endif