private bool AddClientHoldingLock(ForsetiClient client) { while (true) { for (int i = 0; i < _clientsHoldingThisLock.Length; i++) { AtomicReferenceArray <ForsetiClient> holders = _clientsHoldingThisLock[i]; if (holders == null) { holders = AddHolderArray(i); } for (int j = 0; j < holders.length(); j++) { ForsetiClient c = holders.get(j); if (c == null) { // TODO This means we do CAS on each entry, very likely hitting a lot of failures until we // TODO find a slot. We should look into better strategies here. // TODO One such strategy could be binary searching for a free slot, and then linear scan // TODO after that if the CAS fails on the slot we found with binary search. if (holders.compareAndSet(j, null, client)) { return(true); } } } } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReleaseSharedLock() public virtual void ShouldReleaseSharedLock() { // Given ForsetiClient clientA = mock(typeof(ForsetiClient)); SharedLock @lock = new SharedLock(clientA); // When assertTrue(@lock.Release(clientA)); // Then assertThat(@lock.NumberOfHolders(), equalTo(0)); assertThat(@lock.UpdateLock, equalTo(false)); }
public override void CopyHolderWaitListsInto(SimpleBitSet waitList) { foreach (AtomicReferenceArray <ForsetiClient> holders in _clientsHoldingThisLock) { for (int j = 0; holders != null && j < holders.length(); j++) { ForsetiClient client = holders.get(j); if (client != null) { client.CopyWaitListTo(waitList); } } } }
public override int DetectDeadlock(int clientId) { foreach (AtomicReferenceArray <ForsetiClient> holders in _clientsHoldingThisLock) { for (int j = 0; holders != null && j < holders.length(); j++) { ForsetiClient client = holders.get(j); if (client != null && client.IsWaitingFor(clientId)) { return(client.Id()); } } } return(-1); }
private bool ClientHoldsThisLock(ForsetiClient client) { foreach (AtomicReferenceArray <ForsetiClient> holders in _clientsHoldingThisLock) { for (int j = 0; holders != null && j < holders.length(); j++) { ForsetiClient current = holders.get(j); if (current != null && current.Equals(client)) { return(true); } } } return(false); }
public override bool Equals(object o) { if (this == o) { return(true); } if (o == null || this.GetType() != o.GetType()) { return(false); } ForsetiClient that = ( ForsetiClient )o; return(_clientId == that._clientId); }
/// <summary> /// Create a new client to use to grab and release locks. /// </summary> public override Org.Neo4j.Kernel.impl.locking.Locks_Client NewClient() { // We check this volatile closed flag here, which may seem like a contention overhead, but as the time // of writing we apply pooling of transactions and in extension pooling of lock clients, // so this method is called very rarely. if (_closed) { throw new System.InvalidOperationException(this + " already closed"); } ForsetiClient forsetiClient = _clientPool.acquire(); forsetiClient.Reset(); return(forsetiClient); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUpgradeToUpdateLock() public virtual void ShouldUpgradeToUpdateLock() { // Given ForsetiClient clientA = mock(typeof(ForsetiClient)); ForsetiClient clientB = mock(typeof(ForsetiClient)); SharedLock @lock = new SharedLock(clientA); @lock.Acquire(clientB); // When assertTrue(@lock.TryAcquireUpdateLock(clientA)); // Then assertThat(@lock.NumberOfHolders(), equalTo(2)); assertThat(@lock.UpdateLock, equalTo(true)); }
public override void CollectOwners(ISet <ForsetiClient> owners) { foreach (AtomicReferenceArray <ForsetiClient> ownerArray in _clientsHoldingThisLock) { if (ownerArray != null) { int len = ownerArray.length(); for (int i = 0; i < len; i++) { ForsetiClient owner = ownerArray.get(i); if (owner != null) { owners.Add(owner); } } } } }
public virtual bool TryAcquireUpdateLock(ForsetiClient client) { while (true) { int refs = _refCount.get(); if (refs > 0) { if (_refCount.compareAndSet(refs, refs | _updateLockFlag)) { _updateHolder = client; return(true); } } else { return(false); } } }
public override string DescribeWaitList() { StringBuilder sb = new StringBuilder("SharedLock["); foreach (AtomicReferenceArray <ForsetiClient> holders in _clientsHoldingThisLock) { bool first = true; for (int j = 0; holders != null && j < holders.length(); j++) { ForsetiClient current = holders.get(j); if (current != null) { sb.Append(first ? "" : ", ").Append(current.DescribeWaitList()); first = false; } } } return(sb.Append("]").ToString()); }
public virtual bool Acquire(ForsetiClient client) { // First, bump refcount to make sure no one drops this lock on the floor if (!AcquireReference()) { return(false); } // Then add our wait list to the pile of things waiting in case if we are not there yet // if we already waiting we will release a reference to keep counter in sync if (!ClientHoldsThisLock(client)) { // try to add client to a clients that holding current lock. return(AddClientHoldingLock(client)); } else { ReleaseReference(); return(false); } }
private void RemoveClientHoldingLock(ForsetiClient client) { foreach (AtomicReferenceArray <ForsetiClient> holders in _clientsHoldingThisLock) { if (holders == null) { break; } for (int j = 0; j < holders.length(); j++) { ForsetiClient current = holders.get(j); if (current != null && current.Equals(client)) { holders.set(j, null); return; } } } throw new System.InvalidOperationException(client + " asked to be removed from holder list, but it does not hold " + this); }
internal SharedLock(ForsetiClient client) { AddClientHoldingLock(client); }
internal ExclusiveLock(ForsetiClient owner) { this._owner = owner; }
public virtual bool Release(ForsetiClient client) { RemoveClientHoldingLock(client); return(ReleaseReference()); }
public abstract bool shouldAbort(ForsetiClient clientThatsAsking, ForsetiClient clientWereDeadlockedWith);
public ReleaseExclusiveLocksAndClearSharedVisitor(ForsetiClient outerInstance) { this._outerInstance = outerInstance; }
public virtual void CleanUpdateHolder() { _updateHolder = null; }
public ReleaseSharedDontCheckExclusiveVisitor(ForsetiClient outerInstance) { this._outerInstance = outerInstance; }