]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - include/workqueue.h
xfs_repair: don't fail directory repairs when grabbing inodes
[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 struct workqueue;
26
27 typedef void workqueue_func_t(struct workqueue *wq, uint32_t index, void *arg);
28
29 struct workqueue_item {
30 struct workqueue *queue;
31 struct workqueue_item *next;
32 workqueue_func_t *function;
33 void *arg;
34 uint32_t index;
35 };
36
37 struct workqueue {
38 void *wq_ctx;
39 pthread_t *threads;
40 struct workqueue_item *next_item;
41 struct workqueue_item *last_item;
42 pthread_mutex_t lock;
43 pthread_cond_t wakeup;
44 unsigned int item_count;
45 unsigned int thread_count;
46 bool terminate;
47 };
48
49 int workqueue_create(struct workqueue *wq, void *wq_ctx,
50 unsigned int nr_workers);
51 int workqueue_add(struct workqueue *wq, workqueue_func_t fn,
52 uint32_t index, void *arg);
53 void workqueue_destroy(struct workqueue *wq);
54
55 #endif /* _WORKQUEUE_H_ */