1 /* Copyright (c) 2015 Google Inc
2 * Barret Rhoden <brho@cs.berkeley.edu>
3 * See LICENSE for details.
5 * Hacked BSD taskqueues. In lieu of actually running a kproc or something that
6 * sleeps on a queue of tasks, we'll just blast out a kmsg. We can always
7 * change the implementation if we need more control.
10 * Linux workqueue wrappers:
13 * - Workqueues have no core affinity or anything. queued work goes to the
14 * calling core. Scheduled work goes to core 0.
15 * - There are no extra delays in time. All work are RKMs.
16 * - You can't cancel a message. The differences btw work and delayed_work
17 * aren't entirely clear.
22 typedef void (*task_fn_t)(void *context, int pending);
25 task_fn_t ta_func; /* task handler */
26 void *ta_context; /* arg for handler */
29 #define taskqueue_drain(x, y)
30 #define taskqueue_free(x)
31 #define taskqueue_create(a, b, c, d) ((struct taskqueue*)(0xcafebabe))
32 #define taskqueue_create_fast taskqueue_create
33 #define taskqueue_start_threads(a, b, c, d, e) (1)
35 int taskqueue_enqueue(struct taskqueue *queue, struct task *task);
36 /* We're already fast, no need for another function! */
37 #define taskqueue_enqueue_fast taskqueue_enqueue
38 #define TASK_INIT(str, dummy, func, arg) \
39 (str)->ta_func = func; \
40 (str)->ta_context = (void*)arg;
42 struct workqueue_struct {
46 void (*func)(struct work_struct *);
47 /* TODO: args and bookkeeping to support cancel{,_sync}. */
51 /* Delayed work is embedded in other structs. Handlers will expect to get a
52 * work_struct pointer. */
54 struct work_struct work;
55 /* TODO: support for the actual alarm / timer */
58 static inline struct delayed_work *to_delayed_work(struct work_struct *work)
60 return container_of(work, struct delayed_work, work);
63 #define INIT_DELAYED_WORK(dwp, funcp) (dwp)->work.func = (funcp)
64 #define INIT_WORK(wp, funcp) (wp)->func = (funcp)
65 void flush_workqueue(struct workqueue_struct *wq);
66 void destroy_workqueue(struct workqueue_struct *wq);
67 struct workqueue_struct *create_singlethread_workqueue(char *name);
69 bool queue_work(struct workqueue_struct *wq, struct work_struct *dwork);
70 bool schedule_work(struct work_struct *dwork);
71 bool cancel_work(struct work_struct *dwork);
72 bool cancel_work_sync(struct work_struct *dwork);
74 bool queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork,
76 bool schedule_delayed_work(struct delayed_work *dwork, unsigned long delay);
77 bool cancel_delayed_work(struct delayed_work *dwork);
78 bool cancel_delayed_work_sync(struct delayed_work *dwork);