]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libfrog/workqueue.h
libfrog: fix bitmap error communication problems
[thirdparty/xfsprogs-dev.git] / libfrog / workqueue.h
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2017 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 */
6 #ifndef __LIBFROG_WORKQUEUE_H__
7 #define __LIBFROG_WORKQUEUE_H__
8
9 #include <pthread.h>
10
11 struct workqueue;
12
13 typedef void workqueue_func_t(struct workqueue *wq, uint32_t index, void *arg);
14
15 struct workqueue_item {
16 struct workqueue *queue;
17 struct workqueue_item *next;
18 workqueue_func_t *function;
19 void *arg;
20 uint32_t index;
21 };
22
23 struct workqueue {
24 void *wq_ctx;
25 pthread_t *threads;
26 struct workqueue_item *next_item;
27 struct workqueue_item *last_item;
28 pthread_mutex_t lock;
29 pthread_cond_t wakeup;
30 unsigned int item_count;
31 unsigned int thread_count;
32 bool terminate;
33 bool terminated;
34 };
35
36 int workqueue_create(struct workqueue *wq, void *wq_ctx,
37 unsigned int nr_workers);
38 int workqueue_add(struct workqueue *wq, workqueue_func_t fn,
39 uint32_t index, void *arg);
40 int workqueue_terminate(struct workqueue *wq);
41 void workqueue_destroy(struct workqueue *wq);
42
43 #endif /* __LIBFROG_WORKQUEUE_H__ */