// WaitForWriteLockReleaseAsync updates the session in order that there is enough time // to complete the write operation, without the session to terminate. public async Task <IStoredEntry> WaitForWriteLockReleaseAsync(IStoredEntry entry, bool allowWriteLock, CancellationToken cancellation) { var session = await _sessionOwner.GetSessionAsync(cancellation); // The entry was deleted (concurrently). while (entry != null) { var writeLock = entry.WriteLock; if (writeLock == null) { return(entry); } // If (entry.WriteLock == session) we MUST wait till the lock is released // and acquired again in order that no concurrency conflicts may occur. // Because of the case that we may keep a write and read lock at the same time, this does hold true only if we aquire a write lock. // In this case, we could also allow this but had to synchronize the write operations locally. if (writeLock == session) { Assert(allowWriteLock); // If this fails, we have overlapping writes, that should be prevented by the local write lock. return(entry); } var path = entry.Path; if (!await _sessionManager.IsAliveAsync((Session)writeLock, cancellation)) { entry = await CleanupLocksOnSessionTermination(entry, (Session)writeLock, cancellation); continue; } bool IsLockReleased(IStoredEntry e) { if (e.WriteLock == null) { return(true); } if (e.WriteLock == session) { Assert(allowWriteLock); return(true); } return(false); } entry = await WaitForLockReleaseCoreAsync(entry, (Session)writeLock, wait : _lockWaitDirectory.WaitForWriteLockNotificationAsync, acquireLockRelease : null, isLockReleased : IsLockReleased, cancellation); } return(null); }
private async Task <TaskCancellationTokenSource> BuildSessionTerminationSourceAsync(CancellationToken cancellation) { var session = await _sessionOwner.GetSessionAsync(cancellation); var sessionTermination = _sessionManager.WaitForTerminationAsync(session, cancellation); return(new TaskCancellationTokenSource(sessionTermination)); }
private async Task <IPhysicalEndPoint <TAddress> > GetLocalSessionEndPointAsync(CancellationToken cancellation) { var session = await _sessionOwner.GetSessionAsync(cancellation); return(GetSessionEndPoint(session)); }
public ValueTask <Session> GetSessionAsync(CancellationToken cancellation) { return(_sessionOwner.GetSessionAsync(cancellation)); }