static class FSHLog.SafePointZigZagLatch extends Object
Thread A signals Thread B to hold when it gets to a 'safe point'. Thread A wait until Thread B gets there. When the 'safe point' has been attained, Thread B signals Thread A. Thread B then holds at the 'safe point'. Thread A on notification that Thread B is paused, goes ahead and does the work it needs to do while Thread B is holding. When Thread A is done, it flags B and then Thread A and Thread B continue along on their merry way. Pause and signalling 'zigzags' between the two participating threads. We use two latches -- one the inverse of the other -- pausing and signaling when states are achieved.
To start up the drama, Thread A creates an instance of this class each time it would do this
zigzag dance and passes it to Thread B (these classes use Latches so it is one shot only).
Thread B notices the new instance (via reading a volatile reference or how ever) and it starts
to work toward the 'safe point'. Thread A calls waitSafePoint(SyncFuture)
when it
cannot proceed until the Thread B 'safe point' is attained. Thread A will be held inside in
waitSafePoint(SyncFuture)
until Thread B reaches the 'safe point'. Once there, Thread
B frees Thread A by calling safePointAttained()
. Thread A now knows Thread B is at the
'safe point' and that it is holding there (When Thread B calls safePointAttained()
it
blocks here until Thread A calls releaseSafePoint()
). Thread A proceeds to do what it
needs to do while Thread B is paused. When finished, it lets Thread B lose by calling
releaseSafePoint()
and away go both Threads again.
Modifier and Type | Field and Description |
---|---|
private CountDownLatch |
safePointAttainedLatch
Count down this latch when safe point attained.
|
private CountDownLatch |
safePointReleasedLatch
Latch to wait on.
|
Constructor and Description |
---|
SafePointZigZagLatch() |
Modifier and Type | Method and Description |
---|---|
private void |
checkIfSyncFailed(SyncFuture syncFuture) |
(package private) boolean |
isCocked()
Returns True is this is a 'cocked', fresh instance, and not one that has already fired.
|
(package private) boolean |
isSafePointAttained()
Returns if the safepoint has been attained.
|
(package private) void |
releaseSafePoint()
Called by Thread A when it is done with the work it needs to do while Thread B is halted.
|
(package private) void |
safePointAttained()
Called by Thread B when it attains the 'safe point'.
|
(package private) SyncFuture |
waitSafePoint(SyncFuture syncFuture)
For Thread A to call when it is ready to wait on the 'safe point' to be attained.
|
private volatile CountDownLatch safePointAttainedLatch
private volatile CountDownLatch safePointReleasedLatch
SafePointZigZagLatch()
private void checkIfSyncFailed(SyncFuture syncFuture) throws FailedSyncBeforeLogCloseException
SyncFuture waitSafePoint(SyncFuture syncFuture) throws InterruptedException, FailedSyncBeforeLogCloseException
safePointAttained()
syncFuture
- We need this as barometer on outstanding syncs. If it comes home with an
exception, then something is up w/ our syncing.syncFuture
InterruptedException
FailedSyncBeforeLogCloseException
@InterfaceAudience.Private boolean isSafePointAttained()
void safePointAttained() throws InterruptedException
releaseSafePoint()
is called
by Thread A.InterruptedException
void releaseSafePoint()
safePointAttained()
boolean isCocked()
Copyright © 2007–2020 The Apache Software Foundation. All rights reserved.