Blame view

include/linux/spinlock_up.h 2.1 KB
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
1
2
3
4
5
6
  #ifndef __LINUX_SPINLOCK_UP_H
  #define __LINUX_SPINLOCK_UP_H
  
  #ifndef __LINUX_SPINLOCK_H
  # error "please don't include this file directly"
  #endif
d974d905c   Stephen Rothwell   spinlock_up.h: in...
7
  #include <asm/processor.h>	/* for cpu_relax() */
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
8
9
10
11
12
13
14
15
16
17
18
19
20
  /*
   * include/linux/spinlock_up.h - UP-debug version of spinlocks.
   *
   * portions Copyright 2005, Red Hat, Inc., Ingo Molnar
   * Released under the General Public License (GPL).
   *
   * In the debug case, 1 means unlocked, 0 means locked. (the values
   * are inverted, to catch initialization bugs)
   *
   * No atomicity anywhere, we are on UP.
   */
  
  #ifdef CONFIG_DEBUG_SPINLOCK
0199c4e68   Thomas Gleixner   locking: Convert ...
21
  #define arch_spin_is_locked(x)		((x)->slock == 0)
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
22

0199c4e68   Thomas Gleixner   locking: Convert ...
23
  static inline void arch_spin_lock(arch_spinlock_t *lock)
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
24
25
26
27
28
  {
  	lock->slock = 0;
  }
  
  static inline void
0199c4e68   Thomas Gleixner   locking: Convert ...
29
  arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
30
31
32
33
  {
  	local_irq_save(flags);
  	lock->slock = 0;
  }
0199c4e68   Thomas Gleixner   locking: Convert ...
34
  static inline int arch_spin_trylock(arch_spinlock_t *lock)
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
35
36
37
38
39
40
41
  {
  	char oldval = lock->slock;
  
  	lock->slock = 0;
  
  	return oldval > 0;
  }
0199c4e68   Thomas Gleixner   locking: Convert ...
42
  static inline void arch_spin_unlock(arch_spinlock_t *lock)
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
43
44
45
46
47
48
49
  {
  	lock->slock = 1;
  }
  
  /*
   * Read-write spinlocks. No debug version.
   */
e5931943d   Thomas Gleixner   locking: Convert ...
50
51
52
53
54
55
  #define arch_read_lock(lock)		do { (void)(lock); } while (0)
  #define arch_write_lock(lock)		do { (void)(lock); } while (0)
  #define arch_read_trylock(lock)	({ (void)(lock); 1; })
  #define arch_write_trylock(lock)	({ (void)(lock); 1; })
  #define arch_read_unlock(lock)		do { (void)(lock); } while (0)
  #define arch_write_unlock(lock)	do { (void)(lock); } while (0)
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
56
57
  
  #else /* DEBUG_SPINLOCK */
0199c4e68   Thomas Gleixner   locking: Convert ...
58
  #define arch_spin_is_locked(lock)	((void)(lock), 0)
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
59
  /* for sched.c and kernel_lock.c: */
0199c4e68   Thomas Gleixner   locking: Convert ...
60
61
62
63
  # define arch_spin_lock(lock)		do { (void)(lock); } while (0)
  # define arch_spin_lock_flags(lock, flags)	do { (void)(lock); } while (0)
  # define arch_spin_unlock(lock)	do { (void)(lock); } while (0)
  # define arch_spin_trylock(lock)	({ (void)(lock); 1; })
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
64
  #endif /* DEBUG_SPINLOCK */
0199c4e68   Thomas Gleixner   locking: Convert ...
65
  #define arch_spin_is_contended(lock)	(((void)(lock), 0))
95c354fe9   Nick Piggin   spinlock: lockbre...
66

e5931943d   Thomas Gleixner   locking: Convert ...
67
68
  #define arch_read_can_lock(lock)	(((void)(lock), 1))
  #define arch_write_can_lock(lock)	(((void)(lock), 1))
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
69

0199c4e68   Thomas Gleixner   locking: Convert ...
70
71
  #define arch_spin_unlock_wait(lock) \
  		do { cpu_relax(); } while (arch_spin_is_locked(lock))
fb1c8f93d   Ingo Molnar   [PATCH] spinlock ...
72
73
  
  #endif /* __LINUX_SPINLOCK_UP_H */