]>
Commit | Line | Data |
---|---|---|
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 | }; | |
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 | ||
41 | #endif /* __LIBFROG_WORKQUEUE_H__ */ |