]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/workqueue.h
xfs: fix off-by-one error in xfs_rtalloc_query_range
[thirdparty/xfsprogs-dev.git] / include / workqueue.h
1 /*
2 * Copyright (C) 2017 Oracle. All Rights Reserved.
3 *
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it would be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * This code was adapted from repair/threads.h.
21 */
22 #ifndef _WORKQUEUE_H_
23 #define _WORKQUEUE_H_
24
25 #include <pthread.h>
26
27 struct workqueue;
28
29 typedef void workqueue_func_t(struct workqueue *wq, uint32_t index, void *arg);
30
31 struct workqueue_item {
32 struct workqueue *queue;
33 struct workqueue_item *next;
34 workqueue_func_t *function;
35 void *arg;
36 uint32_t index;
37 };
38
39 struct workqueue {
40 void *wq_ctx;
41 pthread_t *threads;
42 struct workqueue_item *next_item;
43 struct workqueue_item *last_item;
44 pthread_mutex_t lock;
45 pthread_cond_t wakeup;
46 unsigned int item_count;
47 unsigned int thread_count;
48 bool terminate;
49 };
50
51 int workqueue_create(struct workqueue *wq, void *wq_ctx,
52 unsigned int nr_workers);
53 int workqueue_add(struct workqueue *wq, workqueue_func_t fn,
54 uint32_t index, void *arg);
55 void workqueue_destroy(struct workqueue *wq);
56
57 #endif /* _WORKQUEUE_H_ */