]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
f434fd95 DW |
2 | /* |
3 | * Copyright (C) 2017 Oracle. All Rights Reserved. | |
f434fd95 | 4 | * Author: Darrick J. Wong <darrick.wong@oracle.com> |
f434fd95 | 5 | */ |
56598728 DW |
6 | #ifndef __LIBFROG_WORKQUEUE_H__ |
7 | #define __LIBFROG_WORKQUEUE_H__ | |
f434fd95 | 8 | |
40b2e298 BS |
9 | #include <pthread.h> |
10 | ||
f434fd95 DW |
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 | }; | |
34 | ||
35 | int workqueue_create(struct workqueue *wq, void *wq_ctx, | |
36 | unsigned int nr_workers); | |
37 | int workqueue_add(struct workqueue *wq, workqueue_func_t fn, | |
38 | uint32_t index, void *arg); | |
39 | void workqueue_destroy(struct workqueue *wq); | |
40 | ||
56598728 | 41 | #endif /* __LIBFROG_WORKQUEUE_H__ */ |