forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit86b9424
committed
Prevent potentially hazardous compiler/cpu reordering during lwlock release.
In LWLockRelease() (and in 9.4+ LWLockUpdateVar()) we release enqueuedwaiters using PGSemaphoreUnlock(). As there are other sources of suchunlocks backends only wake up if MyProc->lwWaiting is set to false;which is only done in the aforementioned functions.Before this commit there were dangers because the store to lwWaitLinkcould become visible before the store to lwWaitLink. This could bothhappen due to compiler reordering (on most compilers) and on someplatforms due to the CPU reordering stores.The possible consequence of this is that a backend stops waitingbefore lwWaitLink is set to NULL. If that backend then tries toacquire another lock and has to wait there the list could becomecorrupted once the lwWaitLink store is finally performed.Add a write memory barrier to prevent that issue.Unfortunately the barrier support has been only added in 9.2. Giventhat the issue has not knowingly been observed in praxis it seemssufficient to prohibit compiler reordering using volatile for 9.0 and9.1. Actual problems due to compiler reordering are more likelyanyway.Discussion: 20140210134625.GA15246@awork2.anarazel.de1 parent789c5b0 commit86b9424
1 file changed
+15
-5
lines changedLines changed: 15 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
647 | 647 |
| |
648 | 648 |
| |
649 | 649 |
| |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
650 | 660 |
| |
651 |
| - | |
652 |
| - | |
653 |
| - | |
654 |
| - | |
655 |
| - | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
656 | 666 |
| |
657 | 667 |
| |
658 | 668 |
| |
|
0 commit comments
Comments
(0)