akaros/kern/include/taskqueue.h
<<
>>
Prefs
   1/* Copyright (c) 2015 Google Inc
   2 * Barret Rhoden <brho@cs.berkeley.edu>
   3 * See LICENSE for details.
   4 *
   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.
   8 *
   9 *
  10 * Linux workqueue wrappers:
  11 *
  12 * Caveats:
  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.
  18 */
  19
  20#pragma once
  21
  22typedef void (*task_fn_t)(void *context, int pending);
  23struct taskqueue {};
  24struct task {
  25        task_fn_t                       ta_func;        /* task handler */
  26        void                            *ta_context;    /* arg for handler */
  27};
  28
  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)
  34
  35int 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;
  41
  42struct workqueue_struct {
  43};
  44
  45struct work_struct {
  46        void (*func)(struct work_struct *);
  47        /* TODO: args and bookkeeping to support cancel{,_sync}. */
  48        void *arg;
  49};
  50
  51/* Delayed work is embedded in other structs.  Handlers will expect to get a
  52 * work_struct pointer. */
  53struct delayed_work {
  54        struct work_struct              work;
  55        /* TODO: support for the actual alarm / timer */
  56};
  57
  58static inline struct delayed_work *to_delayed_work(struct work_struct *work)
  59{
  60        return container_of(work, struct delayed_work, work);
  61}
  62
  63#define INIT_DELAYED_WORK(dwp, funcp) (dwp)->work.func = (funcp)
  64#define INIT_WORK(wp, funcp) (wp)->func = (funcp)
  65void flush_workqueue(struct workqueue_struct *wq);
  66void destroy_workqueue(struct workqueue_struct *wq);
  67struct workqueue_struct *create_singlethread_workqueue(char *name);
  68
  69bool queue_work(struct workqueue_struct *wq, struct work_struct *dwork);
  70bool schedule_work(struct work_struct *dwork);
  71bool cancel_work(struct work_struct *dwork);
  72bool cancel_work_sync(struct work_struct *dwork);
  73
  74bool queue_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork,
  75                        unsigned long delay);
  76bool schedule_delayed_work(struct delayed_work *dwork, unsigned long delay);
  77bool cancel_delayed_work(struct delayed_work *dwork);
  78bool cancel_delayed_work_sync(struct delayed_work *dwork);
  79