Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mutex_64.h
Go to the documentation of this file.
1 /*
2  * Assembly implementation of the mutex fastpath, based on atomic
3  * decrement/increment.
4  *
5  * started by Ingo Molnar:
6  *
7  * Copyright (C) 2004, 2005, 2006 Red Hat, Inc., Ingo Molnar <[email protected]>
8  */
9 #ifndef _ASM_X86_MUTEX_64_H
10 #define _ASM_X86_MUTEX_64_H
11 
19 #define __mutex_fastpath_lock(v, fail_fn) \
20 do { \
21  unsigned long dummy; \
22  \
23  typecheck(atomic_t *, v); \
24  typecheck_fn(void (*)(atomic_t *), fail_fn); \
25  \
26  asm volatile(LOCK_PREFIX " decl (%%rdi)\n" \
27  " jns 1f \n" \
28  " call " #fail_fn "\n" \
29  "1:" \
30  : "=D" (dummy) \
31  : "D" (v) \
32  : "rax", "rsi", "rdx", "rcx", \
33  "r8", "r9", "r10", "r11", "memory"); \
34 } while (0)
35 
47  int (*fail_fn)(atomic_t *))
48 {
49  if (unlikely(atomic_dec_return(count) < 0))
50  return fail_fn(count);
51  else
52  return 0;
53 }
54 
62 #define __mutex_fastpath_unlock(v, fail_fn) \
63 do { \
64  unsigned long dummy; \
65  \
66  typecheck(atomic_t *, v); \
67  typecheck_fn(void (*)(atomic_t *), fail_fn); \
68  \
69  asm volatile(LOCK_PREFIX " incl (%%rdi)\n" \
70  " jg 1f\n" \
71  " call " #fail_fn "\n" \
72  "1:" \
73  : "=D" (dummy) \
74  : "D" (v) \
75  : "rax", "rsi", "rdx", "rcx", \
76  "r8", "r9", "r10", "r11", "memory"); \
77 } while (0)
78 
79 #define __mutex_slowpath_needs_to_unlock() 1
80 
91 static inline int __mutex_fastpath_trylock(atomic_t *count,
92  int (*fail_fn)(atomic_t *))
93 {
94  if (likely(atomic_cmpxchg(count, 1, 0) == 1))
95  return 1;
96  else
97  return 0;
98 }
99 
100 #endif /* _ASM_X86_MUTEX_64_H */