public override void InjectFailure(params Type[] failureTypes) { int count; int newCount; do { count = _countDown.get(); newCount = count - 1; } while (!_countDown.compareAndSet(count, newCount)); if (_resetCountDownOnFailure && newCount < 1) { Reset(); } if (newCount == 0) { try { Thread.Sleep(10); } catch (InterruptedException e) { Console.WriteLine(e.ToString()); Console.Write(e.StackTrace); } ThrowOneOf(failureTypes); } }
/// <summary> /// Move the client to the PREPARE state, unless it is already STOPPED. /// </summary> public void Prepare(Locks_Client client) { int currentValue; int newValue; do { currentValue = _clientState.get(); if (IsStopped(currentValue)) { throw new LockClientStoppedException(client); } newValue = StateWithNewStatus(currentValue, _prepare); } while (!_clientState.compareAndSet(currentValue, newValue)); }
internal virtual bool Increase() { while (true) { int pre = _count.get(); if (pre == DISPOSED_VALUE) { return(false); } else if (_count.compareAndSet(pre, pre + 1)) { return(true); } } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotStartOtherSamplingWhenSamplingAllTheIndexes() public virtual void ShouldNotStartOtherSamplingWhenSamplingAllTheIndexes() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger totalCount = new java.util.concurrent.atomic.AtomicInteger(0); AtomicInteger totalCount = new AtomicInteger(0); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.concurrent.atomic.AtomicInteger concurrentCount = new java.util.concurrent.atomic.AtomicInteger(0); AtomicInteger concurrentCount = new AtomicInteger(0); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch jobLatch = new org.neo4j.test.DoubleLatch(); DoubleLatch jobLatch = new DoubleLatch(); //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.test.DoubleLatch testLatch = new org.neo4j.test.DoubleLatch(); DoubleLatch testLatch = new DoubleLatch(); IndexSamplingJobFactory jobFactory = (_indexId, proxy) => { if (!concurrentCount.compareAndSet(0, 1)) { throw new System.InvalidOperationException("count !== 0 on create"); } totalCount.incrementAndGet(); jobLatch.WaitForAllToStart(); testLatch.StartAndWaitForAllToStart(); jobLatch.WaitForAllToFinish(); concurrentCount.decrementAndGet(); testLatch.Finish(); return(null); }; //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final IndexSamplingController controller = new IndexSamplingController(samplingConfig, jobFactory, jobQueue, tracker, snapshotProvider, scheduler, always(true)); IndexSamplingController controller = new IndexSamplingController(_samplingConfig, jobFactory, _jobQueue, _tracker, _snapshotProvider, _scheduler, Always(true)); when(_tracker.canExecuteMoreSamplingJobs()).thenReturn(true); when(_indexProxy.State).thenReturn(ONLINE); // when running once (new Thread(RunController(controller, TRIGGER_REBUILD_UPDATED))).Start(); jobLatch.StartAndWaitForAllToStart(); testLatch.WaitForAllToStart(); // then blocking on first job assertEquals(1, concurrentCount.get()); // when running a second time controller.SampleIndexes(BACKGROUND_REBUILD_UPDATED); // then no concurrent job execution jobLatch.Finish(); testLatch.WaitForAllToFinish(); // and finally exactly one job has run to completion assertEquals(0, concurrentCount.get()); assertEquals(1, totalCount.get()); }
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 virtual bool Acquire() { return(State.compareAndSet(IDLE, IN_USE)); }
private void TellNextThreadToInitialize() { bool set = _idQueue.compareAndSet(_id - 1, _id); Debug.Assert(set, "Something wrong with the design here"); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: long grabFreeAndExclusivelyLockedPage(org.neo4j.io.pagecache.tracing.PageFaultEvent faultEvent) throws java.io.IOException internal virtual long GrabFreeAndExclusivelyLockedPage(PageFaultEvent faultEvent) { // Review the comment on the freelist field before making changes to // this part of the code. // Whatever the case, we're going to the head-pointer of the freelist, // and in doing so, we can discover a number of things. // We can discover a MuninnPage object, in which case we can try to // CAS the freelist pointer to the value of the MuninnPage.nextFree // pointer, and if this succeeds then we've grabbed that page. // We can discover a FreePage object, in which case we'll do a similar // dance by attempting to CAS the freelist to the FreePage objects next // pointer, and again, if we succeed then we've grabbed the MuninnPage // given by the FreePage object. // We can discover a null-pointer, in which case the freelist has just // been emptied for whatever it contained before. New FreePage objects // are eventually going to be added to the freelist, but we are not // going to wait around for that to happen. If the freelist is empty, // then we do our own eviction to get a free page. // If we find a FreePage object on the freelist, then it is important // to check and see if it is the shutdownSignal instance. If that's the // case, then the page cache has been shut down, and we should throw an // exception from our page fault routine. object current; for ( ;;) { AssertHealthy(); current = FreelistHead; if (current == null) { UnparkEvictor(); long pageRef = CooperativelyEvict(faultEvent); if (pageRef != 0) { return(pageRef); } } else if (current is AtomicInteger) { int pageCount = Pages.PageCount; AtomicInteger counter = ( AtomicInteger )current; int pageId = counter.get(); if (pageId < pageCount && counter.compareAndSet(pageId, pageId + 1)) { return(Pages.deref(pageId)); } if (pageId >= pageCount) { CompareAndSetFreelistHead(current, null); } } else if (current is FreePage) { FreePage freePage = ( FreePage )current; if (freePage == _shutdownSignal) { throw new System.InvalidOperationException("The PageCache has been shut down."); } if (CompareAndSetFreelistHead(freePage, freePage.NextConflict)) { return(freePage.PageRef); } } } }