Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit689c815

Browse files
author
Neil Conway
committed
Add a comment describing the requirement that pointers into shared memory
that is protected by a spinlock must be volatile, per recent discussion.
1 parent4a6dcf0 commit689c815

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

‎src/include/storage/spin.h

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77
*The hardware-independent interface to spinlocks is defined by the
88
*typedef "slock_t" and these macros:
99
*
10-
*void SpinLockInit(slock_t *lock)
10+
*void SpinLockInit(volatileslock_t *lock)
1111
*Initialize a spinlock (to the unlocked state).
1212
*
13-
*void SpinLockAcquire(slock_t *lock)
13+
*void SpinLockAcquire(volatileslock_t *lock)
1414
*Acquire a spinlock, waiting if necessary.
1515
*Time out and abort() if unable to acquire the lock in a
1616
*"reasonable" amount of time --- typically ~ 1 minute.
1717
*Cancel/die interrupts are held off until the lock is released.
1818
*
19-
*void SpinLockRelease(slock_t *lock)
19+
*void SpinLockRelease(volatileslock_t *lock)
2020
*Unlock a previously acquired lock.
2121
*Release the cancel/die interrupt holdoff.
2222
*
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)
2525
*Same as above, except no interrupt holdoff processing is done.
2626
*This pair of macros may be used when there is a surrounding
2727
*interrupt holdoff.
@@ -33,14 +33,24 @@
3333
*Callers must beware that the macro argument may be evaluated multiple
3434
*times!
3535
*
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
3747
*supplied by s_lock.h.
3848
*
3949
*
4050
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
4151
* Portions Copyright (c) 1994, Regents of the University of California
4252
*
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 $
4454
*
4555
*-------------------------------------------------------------------------
4656
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp