Subversion Repositories Kolibri OS

Rev

Rev 1616 | Rev 1967 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Mutexes: blocking mutual exclusion locks
  3.  *
  4.  * started by Ingo Molnar:
  5.  *
  6.  *  Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
  7.  *
  8.  * This file contains the main data structure and API definitions.
  9.  */
  10. #ifndef __LINUX_MUTEX_H
  11. #define __LINUX_MUTEX_H
  12.  
  13. #include <linux/list.h>
  14. #include <asm/atomic.h>
  15.  
  16. /*
  17.  * Simple, straightforward mutexes with strict semantics:
  18.  *
  19.  * - only one task can hold the mutex at a time
  20.  * - only the owner can unlock the mutex
  21.  * - multiple unlocks are not permitted
  22.  * - recursive locking is not permitted
  23.  * - a mutex object must be initialized via the API
  24.  * - a mutex object must not be initialized via memset or copying
  25.  * - task may not exit with mutex held
  26.  * - memory areas where held locks reside must not be freed
  27.  * - held mutexes must not be reinitialized
  28.  * - mutexes may not be used in hardware or software interrupt
  29.  *   contexts such as tasklets and timers
  30.  *
  31.  * These semantics are fully enforced when DEBUG_MUTEXES is
  32.  * enabled. Furthermore, besides enforcing the above rules, the mutex
  33.  * debugging code also implements a number of additional features
  34.  * that make lock debugging easier and faster:
  35.  *
  36.  * - uses symbolic names of mutexes, whenever they are printed in debug output
  37.  * - point-of-acquire tracking, symbolic lookup of function names
  38.  * - list of all locks held in the system, printout of them
  39.  * - owner tracking
  40.  * - detects self-recursing locks and prints out all relevant info
  41.  * - detects multi-task circular deadlocks and prints out all affected
  42.  *   locks and tasks (and only those tasks)
  43.  */
  44. struct mutex {
  45.         /* 1: unlocked, 0: locked, negative: locked, possible waiters */
  46.         atomic_t                count;
  47.         struct list_head        wait_list;
  48. };
  49.  
  50. /*
  51.  * This is the control structure for tasks blocked on mutex,
  52.  * which resides on the blocked task's kernel stack:
  53.  */
  54. struct mutex_waiter {
  55.         struct list_head        list;
  56.     int                *task;
  57. };
  58.  
  59. void __attribute__ ((fastcall)) __attribute__ ((dllimport))
  60.      mutex_init(struct mutex*)__asm__("MutexInit");
  61. void __attribute__ ((fastcall)) __attribute__ ((dllimport))
  62.      mutex_lock(struct mutex*)__asm__("MutexLock");
  63. void __attribute__ ((fastcall)) __attribute__ ((dllimport))
  64.      mutex_unlock(struct mutex*)__asm__("MutexUnlock");
  65.  
  66. /**
  67.  * mutex_is_locked - is the mutex locked
  68.  * @lock: the mutex to be queried
  69.  *
  70.  * Returns 1 if the mutex is locked, 0 if unlocked.
  71.  */
  72. static inline int mutex_is_locked(struct mutex *lock)
  73. {
  74.         return atomic_read(&lock->count) != 1;
  75. }
  76.  
  77. #endif
  78.