akaros/kern/include/rwlock.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 * Reader-writer queue locks (sleeping locks).
   6 *
   7 * Readers favor readers; writers favor writers.  Check out rwlock.c for more
   8 * info.
   9 *
  10 * One consequence of this: "if some reader holds a rwlock, then any other
  11 * thread (including itself) can get an rlock". */
  12
  13#pragma once
  14
  15#include <ros/common.h>
  16#include <kthread.h>
  17#include <atomic.h>
  18
  19struct rwlock {
  20        spinlock_t                      lock;
  21        atomic_t                        nr_readers;
  22        bool                            writing;
  23        struct cond_var                 readers;
  24        struct cond_var                 writers;
  25};
  26typedef struct rwlock rwlock_t;
  27
  28void rwinit(struct rwlock *rw_lock);
  29void rlock(struct rwlock *rw_lock);
  30bool canrlock(struct rwlock *rw_lock);
  31void runlock(struct rwlock *rw_lock);
  32void wlock(struct rwlock *rw_lock);
  33void wunlock(struct rwlock *rw_lock);
  34