|
7 | 7 | *The hardware-independent interface to spinlocks is defined by the |
8 | 8 | *typedef "slock_t" and these macros: |
9 | 9 | * |
10 | | - *void SpinLockInit(slock_t *lock) |
| 10 | + *void SpinLockInit(volatileslock_t *lock) |
11 | 11 | *Initialize a spinlock (to the unlocked state). |
12 | 12 | * |
13 | | - *void SpinLockAcquire(slock_t *lock) |
| 13 | + *void SpinLockAcquire(volatileslock_t *lock) |
14 | 14 | *Acquire a spinlock, waiting if necessary. |
15 | 15 | *Time out and abort() if unable to acquire the lock in a |
16 | 16 | *"reasonable" amount of time --- typically ~ 1 minute. |
17 | 17 | *Cancel/die interrupts are held off until the lock is released. |
18 | 18 | * |
19 | | - *void SpinLockRelease(slock_t *lock) |
| 19 | + *void SpinLockRelease(volatileslock_t *lock) |
20 | 20 | *Unlock a previously acquired lock. |
21 | 21 | *Release the cancel/die interrupt holdoff. |
22 | 22 | * |
23 | | - *void SpinLockAcquire_NoHoldoff(slock_t *lock) |
24 | | - *void SpinLockRelease_NoHoldoff(slock_t *lock) |
| 23 | + *void SpinLockAcquire_NoHoldoff(volatileslock_t *lock) |
| 24 | + *void SpinLockRelease_NoHoldoff(volatileslock_t *lock) |
25 | 25 | *Same as above, except no interrupt holdoff processing is done. |
26 | 26 | *This pair of macros may be used when there is a surrounding |
27 | 27 | *interrupt holdoff. |
|
33 | 33 | *Callers must beware that the macro argument may be evaluated multiple |
34 | 34 | *times! |
35 | 35 | * |
36 | | - *The macros are implemented in terms of hardware-dependent macros |
| 36 | + *CAUTION: Care must be taken to ensure that loads and stores of |
| 37 | + *shared memory values are not rearranged around spinlock acquire |
| 38 | + *and release. This is done using the "volatile" qualifier: the C |
| 39 | + *standard states that loads and stores of volatile objects cannot |
| 40 | + *be rearranged *with respect to other volatile objects*. The |
| 41 | + *spinlock is always written through a volatile pointer by the |
| 42 | + *spinlock macros, but this is not sufficient by itself: code that |
| 43 | + *protects shared data with a spinlock MUST reference that shared |
| 44 | + *data through a volatile pointer. |
| 45 | + * |
| 46 | + *These macros are implemented in terms of hardware-dependent macros |
37 | 47 | *supplied by s_lock.h. |
38 | 48 | * |
39 | 49 | * |
40 | 50 | * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group |
41 | 51 | * Portions Copyright (c) 1994, Regents of the University of California |
42 | 52 | * |
43 | | - * $PostgreSQL: pgsql/src/include/storage/spin.h,v 1.25 2004/12/31 22:03:42 pgsql Exp $ |
| 53 | + * $PostgreSQL: pgsql/src/include/storage/spin.h,v 1.26 2005/10/13 06:17:34 neilc Exp $ |
44 | 54 | * |
45 | 55 | *------------------------------------------------------------------------- |
46 | 56 | */ |
|