|
24 | 24 | * Tests if the lock is free. Returns TRUE if free, FALSE if locked.
|
25 | 25 | * This does *not* change the state of the lock.
|
26 | 26 | *
|
| 27 | + * void SPIN_DELAY(void) |
| 28 | + * Delay operation to occur inside spinlock wait loop. |
| 29 | + * |
27 | 30 | * Note to implementors: there are default implementations for all these
|
28 | 31 | * macros at the bottom of the file. Check if your platform can use
|
29 | 32 | * these or needs to override them.
|
|
63 | 66 | * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
64 | 67 | * Portions Copyright (c) 1994, Regents of the University of California
|
65 | 68 | *
|
66 |
| - * $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.123 2003/12/23 22:15:07 tgl Exp $ |
| 69 | + * $PostgreSQL: pgsql/src/include/storage/s_lock.h,v 1.124 2003/12/27 20:58:58 tgl Exp $ |
67 | 70 | *
|
68 | 71 | *-------------------------------------------------------------------------
|
69 | 72 | */
|
@@ -107,14 +110,28 @@ tas(volatile slock_t *lock)
|
107 | 110 | {
|
108 | 111 | register slock_t _res = 1;
|
109 | 112 |
|
| 113 | + /* Use a non-locking test before asserting the bus lock */ |
110 | 114 | __asm__ __volatile__(
|
| 115 | + " cmpb $0,%1 \n" |
| 116 | + " jne 1f \n" |
111 | 117 | " lock \n"
|
112 | 118 | " xchgb %0,%1 \n"
|
| 119 | + "1: \n" |
113 | 120 | : "=q"(_res), "=m"(*lock)
|
114 | 121 | : "0"(_res));
|
115 | 122 | return (int) _res;
|
116 | 123 | }
|
117 | 124 |
|
| 125 | +#define SPIN_DELAY() spin_delay() |
| 126 | + |
| 127 | +static __inline__ void |
| 128 | +spin_delay(void) |
| 129 | +{ |
| 130 | + __asm__ __volatile__( |
| 131 | + " rep; nop \n" |
| 132 | + : : : "memory"); |
| 133 | +} |
| 134 | + |
118 | 135 | #endif /* __i386__ || __x86_64__ */
|
119 | 136 |
|
120 | 137 |
|
@@ -708,6 +725,10 @@ extern int tas_sema(volatile slock_t *lock);
|
708 | 725 | #define S_INIT_LOCK(lock) S_UNLOCK(lock)
|
709 | 726 | #endif /* S_INIT_LOCK */
|
710 | 727 |
|
| 728 | +#if !defined(SPIN_DELAY) |
| 729 | +#define SPIN_DELAY() ((void) 0) |
| 730 | +#endif /* SPIN_DELAY */ |
| 731 | + |
711 | 732 | #if !defined(TAS)
|
712 | 733 | extern int tas(volatile slock_t *lock); /* in port/.../tas.s, or
|
713 | 734 | * s_lock.c */
|
|
0 commit comments