Commit | Line | Data |
---|---|---|
ccacf27f MD |
1 | #ifndef _URCU_WORKQUEUE_H |
2 | #define _URCU_WORKQUEUE_H | |
3 | ||
4 | /* | |
5 | * workqueue.h | |
6 | * | |
7 | * Userspace RCU header - Userspace workqueues | |
8 | * | |
9 | * Copyright (c) 2009,2017 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
10 | * Copyright (c) 2009 Paul E. McKenney, IBM Corporation. | |
11 | * | |
12 | * This library is free software; you can redistribute it and/or | |
13 | * modify it under the terms of the GNU Lesser General Public | |
14 | * License as published by the Free Software Foundation; either | |
15 | * version 2.1 of the License, or (at your option) any later version. | |
16 | * | |
17 | * This library is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 | * Lesser General Public License for more details. | |
21 | * | |
22 | * You should have received a copy of the GNU Lesser General Public | |
23 | * License along with this library; if not, write to the Free Software | |
24 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
25 | */ | |
26 | ||
27 | #include <stdlib.h> | |
28 | #include <pthread.h> | |
29 | ||
30 | #include <urcu/wfcqueue.h> | |
31 | ||
32 | #ifdef __cplusplus | |
33 | extern "C" { | |
34 | #endif | |
35 | ||
36 | /* Note that struct urcu_workqueue is opaque to callers. */ | |
37 | ||
38 | struct urcu_workqueue; | |
39 | struct urcu_workqueue_completion; | |
40 | ||
41 | /* Flag values. */ | |
42 | ||
43 | #define URCU_WORKQUEUE_RT (1U << 0) | |
44 | #define URCU_WORKQUEUE_STOP (1U << 1) | |
45 | #define URCU_WORKQUEUE_PAUSE (1U << 2) | |
46 | #define URCU_WORKQUEUE_PAUSED (1U << 3) | |
47 | ||
48 | /* | |
49 | * The urcu_work data structure is placed in the structure to be acted | |
50 | * upon via urcu_workqueue_queue_work(). | |
51 | */ | |
52 | ||
53 | struct urcu_work { | |
54 | struct cds_wfcq_node next; | |
55 | void (*func)(struct urcu_work *head); | |
56 | }; | |
57 | ||
58 | /* | |
59 | * Exported functions | |
60 | */ | |
61 | ||
62 | struct urcu_workqueue *urcu_workqueue_create(unsigned long flags, | |
63 | int cpu_affinity, void *priv, | |
64 | void (*grace_period_fct)(struct urcu_workqueue *workqueue, void *priv), | |
65 | void (*initialize_worker_fct)(struct urcu_workqueue *workqueue, void *priv), | |
66 | void (*finalize_worker_fct)(struct urcu_workqueue *workqueue, void *priv), | |
67 | void (*worker_before_wait_fct)(struct urcu_workqueue *workqueue, void *priv), | |
68 | void (*worker_after_wake_up_fct)(struct urcu_workqueue *workqueue, void *priv), | |
69 | void (*worker_before_pause_fct)(struct urcu_workqueue *workqueue, void *priv), | |
70 | void (*worker_after_resume_fct)(struct urcu_workqueue *workqueue, void *priv)); | |
71 | void urcu_workqueue_destroy(struct urcu_workqueue *workqueue); | |
72 | ||
73 | /* | |
74 | * Never fails. Should not be used to enqueue work from worker threads | |
75 | * after the application invokes urcu_workqueue_free. | |
76 | */ | |
77 | void urcu_workqueue_queue_work(struct urcu_workqueue *workqueue, | |
78 | struct urcu_work *work, | |
79 | void (*func)(struct urcu_work *work)); | |
80 | ||
81 | struct urcu_workqueue_completion *urcu_workqueue_create_completion(void); | |
82 | void urcu_workqueue_destroy_completion(struct urcu_workqueue_completion *completion); | |
83 | ||
84 | void urcu_workqueue_queue_completion(struct urcu_workqueue *workqueue, | |
85 | struct urcu_workqueue_completion *completion); | |
86 | void urcu_workqueue_wait_completion(struct urcu_workqueue_completion *completion); | |
87 | ||
88 | void urcu_workqueue_flush_queued_work(struct urcu_workqueue *workqueue); | |
89 | ||
90 | /* | |
91 | * pause/resume/create worker threads. Can be used to pause worker | |
92 | * threads across fork/clone while keeping the workqueue in place. | |
93 | * Pause is used in parent pre-fork, resume in parent post-fork, create | |
94 | * in child after-fork. | |
95 | */ | |
96 | void urcu_workqueue_pause_worker(struct urcu_workqueue *workqueue); | |
97 | void urcu_workqueue_resume_worker(struct urcu_workqueue *workqueue); | |
98 | void urcu_workqueue_create_worker(struct urcu_workqueue *workqueue); | |
99 | ||
100 | #ifdef __cplusplus | |
101 | } | |
102 | #endif | |
103 | ||
104 | #endif /* _URCU_WORKQUEUE_H */ |