slab: introduce kzfree()
[safe/jmp/linux-2.6] / include / linux / spinlock.h
index a946176..a0c66a2 100644 (file)
@@ -46,6 +46,7 @@
  *  linux/spinlock.h:     builds the final spin_*() APIs.
  */
 
+#include <linux/typecheck.h>
 #include <linux/preempt.h>
 #include <linux/linkage.h>
 #include <linux/compiler.h>
@@ -71,7 +72,7 @@
 #define LOCK_SECTION_END                        \
         ".previous\n\t"
 
-#define __lockfunc fastcall __attribute__((section(".spinlock.text")))
+#define __lockfunc __attribute__((section(".spinlock.text")))
 
 /*
  * Pull the raw_spinlock_t and raw_rwlock_t definitions:
@@ -120,6 +121,17 @@ do {                                                               \
 
 #define spin_is_locked(lock)   __raw_spin_is_locked(&(lock)->raw_lock)
 
+#ifdef CONFIG_GENERIC_LOCKBREAK
+#define spin_is_contended(lock) ((lock)->break_lock)
+#else
+
+#ifdef __raw_spin_is_contended
+#define spin_is_contended(lock)        __raw_spin_is_contended(&(lock)->raw_lock)
+#else
+#define spin_is_contended(lock)        (((void)(lock), 0))
+#endif /*__raw_spin_is_contended*/
+#endif
+
 /**
  * spin_unlock_wait - wait until the spinlock gets unlocked
  * @lock: the spinlock in question.
@@ -176,8 +188,14 @@ do {                                                               \
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 # define spin_lock_nested(lock, subclass) _spin_lock_nested(lock, subclass)
+# define spin_lock_nest_lock(lock, nest_lock)                          \
+        do {                                                           \
+                typecheck(struct lockdep_map *, &(nest_lock)->dep_map);\
+                _spin_lock_nest_lock(lock, &(nest_lock)->dep_map);     \
+        } while (0)
 #else
 # define spin_lock_nested(lock, subclass) _spin_lock(lock)
+# define spin_lock_nest_lock(lock, nest_lock) _spin_lock(lock)
 #endif
 
 #define write_lock(lock)               _write_lock(lock)
@@ -185,23 +203,53 @@ do {                                                              \
 
 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK)
 
-#define spin_lock_irqsave(lock, flags) flags = _spin_lock_irqsave(lock)
-#define read_lock_irqsave(lock, flags) flags = _read_lock_irqsave(lock)
-#define write_lock_irqsave(lock, flags)        flags = _write_lock_irqsave(lock)
+#define spin_lock_irqsave(lock, flags)                 \
+       do {                                            \
+               typecheck(unsigned long, flags);        \
+               flags = _spin_lock_irqsave(lock);       \
+       } while (0)
+#define read_lock_irqsave(lock, flags)                 \
+       do {                                            \
+               typecheck(unsigned long, flags);        \
+               flags = _read_lock_irqsave(lock);       \
+       } while (0)
+#define write_lock_irqsave(lock, flags)                        \
+       do {                                            \
+               typecheck(unsigned long, flags);        \
+               flags = _write_lock_irqsave(lock);      \
+       } while (0)
 
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
-#define spin_lock_irqsave_nested(lock, flags, subclass) \
-       flags = _spin_lock_irqsave_nested(lock, subclass)
+#define spin_lock_irqsave_nested(lock, flags, subclass)                        \
+       do {                                                            \
+               typecheck(unsigned long, flags);                        \
+               flags = _spin_lock_irqsave_nested(lock, subclass);      \
+       } while (0)
 #else
-#define spin_lock_irqsave_nested(lock, flags, subclass) \
-       flags = _spin_lock_irqsave(lock)
+#define spin_lock_irqsave_nested(lock, flags, subclass)                        \
+       do {                                                            \
+               typecheck(unsigned long, flags);                        \
+               flags = _spin_lock_irqsave(lock);                       \
+       } while (0)
 #endif
 
 #else
 
-#define spin_lock_irqsave(lock, flags) _spin_lock_irqsave(lock, flags)
-#define read_lock_irqsave(lock, flags) _read_lock_irqsave(lock, flags)
-#define write_lock_irqsave(lock, flags)        _write_lock_irqsave(lock, flags)
+#define spin_lock_irqsave(lock, flags)                 \
+       do {                                            \
+               typecheck(unsigned long, flags);        \
+               _spin_lock_irqsave(lock, flags);        \
+       } while (0)
+#define read_lock_irqsave(lock, flags)                 \
+       do {                                            \
+               typecheck(unsigned long, flags);        \
+               _read_lock_irqsave(lock, flags);        \
+       } while (0)
+#define write_lock_irqsave(lock, flags)                        \
+       do {                                            \
+               typecheck(unsigned long, flags);        \
+               _write_lock_irqsave(lock, flags);       \
+       } while (0)
 #define spin_lock_irqsave_nested(lock, flags, subclass)        \
        spin_lock_irqsave(lock, flags)
 
@@ -254,16 +302,25 @@ do {                                              \
 } while (0)
 #endif
 
-#define spin_unlock_irqrestore(lock, flags) \
-                                       _spin_unlock_irqrestore(lock, flags)
+#define spin_unlock_irqrestore(lock, flags)            \
+       do {                                            \
+               typecheck(unsigned long, flags);        \
+               _spin_unlock_irqrestore(lock, flags);   \
+       } while (0)
 #define spin_unlock_bh(lock)           _spin_unlock_bh(lock)
 
-#define read_unlock_irqrestore(lock, flags) \
-                                       _read_unlock_irqrestore(lock, flags)
+#define read_unlock_irqrestore(lock, flags)            \
+       do {                                            \
+               typecheck(unsigned long, flags);        \
+               _read_unlock_irqrestore(lock, flags);   \
+       } while (0)
 #define read_unlock_bh(lock)           _read_unlock_bh(lock)
 
-#define write_unlock_irqrestore(lock, flags) \
-                                       _write_unlock_irqrestore(lock, flags)
+#define write_unlock_irqrestore(lock, flags)           \
+       do {                                            \
+               typecheck(unsigned long, flags);        \
+               _write_unlock_irqrestore(lock, flags);  \
+       } while (0)
 #define write_unlock_bh(lock)          _write_unlock_bh(lock)
 
 #define spin_trylock_bh(lock)  __cond_lock(lock, _spin_trylock_bh(lock))
@@ -282,42 +339,12 @@ do {                                              \
        1 : ({ local_irq_restore(flags); 0; }); \
 })
 
-/*
- * Locks two spinlocks l1 and l2.
- * l1_first indicates if spinlock l1 should be taken first.
- */
-static inline void double_spin_lock(spinlock_t *l1, spinlock_t *l2,
-                                   bool l1_first)
-       __acquires(l1)
-       __acquires(l2)
-{
-       if (l1_first) {
-               spin_lock(l1);
-               spin_lock(l2);
-       } else {
-               spin_lock(l2);
-               spin_lock(l1);
-       }
-}
-
-/*
- * Unlocks two spinlocks l1 and l2.
- * l1_taken_first indicates if spinlock l1 was taken first and therefore
- * should be released after spinlock l2.
- */
-static inline void double_spin_unlock(spinlock_t *l1, spinlock_t *l2,
-                                     bool l1_taken_first)
-       __releases(l1)
-       __releases(l2)
-{
-       if (l1_taken_first) {
-               spin_unlock(l2);
-               spin_unlock(l1);
-       } else {
-               spin_unlock(l1);
-               spin_unlock(l2);
-       }
-}
+#define write_trylock_irqsave(lock, flags) \
+({ \
+       local_irq_save(flags); \
+       write_trylock(lock) ? \
+       1 : ({ local_irq_restore(flags); 0; }); \
+})
 
 /*
  * Pull the atomic_t declaration:
@@ -328,6 +355,9 @@ static inline void double_spin_unlock(spinlock_t *l1, spinlock_t *l2,
  * atomic_dec_and_lock - lock on reaching reference count zero
  * @atomic: the atomic counter
  * @lock: the spinlock in question
+ *
+ * Decrements @atomic by 1.  If the result is 0, returns true and locks
+ * @lock.  Returns false for all other cases.
  */
 extern int _atomic_dec_and_lock(atomic_t *atomic, spinlock_t *lock);
 #define atomic_dec_and_lock(atomic, lock) \