linux/include/linux/rwsem.h
<<
>>
Prefs
   1/* rwsem.h: R/W semaphores, public interface
   2 *
   3 * Written by David Howells (dhowells@redhat.com).
   4 * Derived from asm-i386/semaphore.h
   5 */
   6
   7#ifndef _LINUX_RWSEM_H
   8#define _LINUX_RWSEM_H
   9
  10#include <linux/linkage.h>
  11
  12#include <linux/types.h>
  13#include <linux/kernel.h>
  14#include <asm/system.h>
  15#include <asm/atomic.h>
  16
  17struct rw_semaphore;
  18
  19#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
  20#include <linux/rwsem-spinlock.h> /* use a generic implementation */
  21#else
  22#include <asm/rwsem.h> /* use an arch-specific implementation */
  23#endif
  24
  25/*
  26 * lock for reading
  27 */
  28extern void down_read(struct rw_semaphore *sem);
  29
  30/*
  31 * trylock for reading -- returns 1 if successful, 0 if contention
  32 */
  33extern int down_read_trylock(struct rw_semaphore *sem);
  34
  35/*
  36 * lock for writing
  37 */
  38extern void down_write(struct rw_semaphore *sem);
  39
  40/*
  41 * trylock for writing -- returns 1 if successful, 0 if contention
  42 */
  43extern int down_write_trylock(struct rw_semaphore *sem);
  44
  45/*
  46 * release a read lock
  47 */
  48extern void up_read(struct rw_semaphore *sem);
  49
  50/*
  51 * release a write lock
  52 */
  53extern void up_write(struct rw_semaphore *sem);
  54
  55/*
  56 * downgrade write lock to read lock
  57 */
  58extern void downgrade_write(struct rw_semaphore *sem);
  59
  60#ifdef CONFIG_DEBUG_LOCK_ALLOC
  61/*
  62 * nested locking. NOTE: rwsems are not allowed to recurse
  63 * (which occurs if the same task tries to acquire the same
  64 * lock instance multiple times), but multiple locks of the
  65 * same lock class might be taken, if the order of the locks
  66 * is always the same. This ordering rule can be expressed
  67 * to lockdep via the _nested() APIs, but enumerating the
  68 * subclasses that are used. (If the nesting relationship is
  69 * static then another method for expressing nested locking is
  70 * the explicit definition of lock class keys and the use of
  71 * lockdep_set_class() at lock initialization time.
  72 * See Documentation/lockdep-design.txt for more details.)
  73 */
  74extern void down_read_nested(struct rw_semaphore *sem, int subclass);
  75extern void down_write_nested(struct rw_semaphore *sem, int subclass);
  76/*
  77 * Take/release a lock when not the owner will release it.
  78 *
  79 * [ This API should be avoided as much as possible - the
  80 *   proper abstraction for this case is completions. ]
  81 */
  82extern void down_read_non_owner(struct rw_semaphore *sem);
  83extern void up_read_non_owner(struct rw_semaphore *sem);
  84#else
  85# define down_read_nested(sem, subclass)                down_read(sem)
  86# define down_write_nested(sem, subclass)       down_write(sem)
  87# define down_read_non_owner(sem)               down_read(sem)
  88# define up_read_non_owner(sem)                 up_read(sem)
  89#endif
  90
  91#endif /* _LINUX_RWSEM_H */
  92