akaros/kern/include/rendez.h
<<
>>
Prefs
   1/* Copyright (c) 2013 The Regents of the University of California
   2 * Barret Rhoden <brho@cs.berkeley.edu>
   3 * See LICENSE for details.
   4 *
   5 * Plan9 style Rendezvous (http://plan9.bell-labs.com/sys/doc/sleep.html)
   6 *
   7 * We implement it with CVs, and it can handle multiple sleepers/wakers.
   8 *
   9 * Init:
  10 *      rendez_init(&rv);
  11 *
  12 * Sleeper usage:
  13 *      rendez_sleep(&rv, some_func_taking_void*, void *arg);
  14 *                      or
  15 *      rendez_sleep_timeout(&rv, some_func_taking_void*, void *arg, usec);
  16 *
  17 * Waker usage: (can be used from IRQ context)
  18 *      // set the condition to TRUE, then:
  19 *      rendez_wakeup(&rv);
  20 *
  21 * Some notes:
  22 * - Some_func checks some condition and returns TRUE when we want to wake up.
  23 * - Sleep returns when the condition is true and when it has been woken up.
  24 *   It can return without sleeping or requiring a wakeup if the condition is
  25 *   already true.
  26 * - Wakers should set the condition, then trigger the wakeup to ensure the
  27 *   sleeper has awakened.  (internal locks provide the needed barriers).
  28 * - Timeout sleep is like regular sleep, with the addition that it will return
  29 *   after some milliseconds, regardless of the condition.
  30 * - The only locking/protection is done internally.  In plan9, they expect to
  31 *   only have one sleeper and one waker.  So your code around the rendez needs
  32 *   to take that into account.  The old plan9 code should already do this.
  33 *
  34 * - TODO: i dislike the int vs bool on the func pointer.  prob would need to
  35 *   change all 9ns rendez functions
  36 */
  37
  38#pragma once
  39
  40#include <ros/common.h>
  41#include <kthread.h>
  42#include <alarm.h>
  43
  44struct rendez {
  45        struct cond_var                 cv;
  46};
  47
  48typedef int (*rendez_cond_t)(void *arg);
  49
  50void rendez_init(struct rendez *rv);
  51void rendez_sleep(struct rendez *rv, int (*cond)(void*), void *arg);
  52void rendez_sleep_timeout(struct rendez *rv, int (*cond)(void*), void *arg,
  53                          uint64_t usec);
  54bool rendez_wakeup(struct rendez *rv);
  55void rendez_debug_waiter(struct alarm_waiter *awaiter);
  56