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

Commit4433eb1

Browse files
committed
Make sure that inlined S_UNLOCK is marked as an update of a 'volatile'
object. This should prevent the compiler from reordering loads and storesinto or out of a critical section.
1 parent0700965 commit4433eb1

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

‎src/include/storage/s_lock.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
*will "fail" if interrupted. Therefore TAS() should always be invoked
4444
*in a retry loop, even if you are certain the lock is free.
4545
*
46+
*ANOTHER CAUTION: be sure that TAS() and S_UNLOCK() represent sequence
47+
*points, ie, loads and stores of other values must not be moved across
48+
*a lock or unlock. In most cases it suffices to make the operation be
49+
*done through a "volatile" pointer.
50+
*
4651
*On most supported platforms, TAS() uses a tas() function written
4752
*in assembly language to execute a hardware atomic-test-and-set
4853
*instruction. Equivalent OS-supplied mutex routines could be used too.
@@ -58,7 +63,7 @@
5863
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
5964
* Portions Copyright (c) 1994, Regents of the University of California
6065
*
61-
* $Id: s_lock.h,v 1.95 2001/09/29 04:02:26 tgl Exp $
66+
* $Id: s_lock.h,v 1.96 2001/12/1102:58:49 tgl Exp $
6267
*
6368
*-------------------------------------------------------------------------
6469
*/
@@ -306,7 +311,7 @@ tas(volatile slock_t *s_lock)
306311
do \
307312
{\
308313
__asm__ __volatile__ ("mb \n"); \
309-
*(lock) = 0; \
314+
*((volatile slock_t *) (lock)) = 0; \
310315
} while (0)
311316

312317
static __inline__int
@@ -500,7 +505,7 @@ extern inttas_sema(volatile slock_t *lock);
500505
#endif/* S_LOCK_FREE */
501506

502507
#if !defined(S_UNLOCK)
503-
#defineS_UNLOCK(lock)(*(lock) = 0)
508+
#defineS_UNLOCK(lock)(*((volatile slock_t *) (lock)) = 0)
504509
#endif/* S_UNLOCK */
505510

506511
#if !defined(S_INIT_LOCK)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp