private long GetPlaceForNewContinuationGraphElements(int number) { var locationOfFirstNewEntry = InterlockedExtensions.AddFetch(ref _continuationGraphElementCount, number); if (locationOfFirstNewEntry + number >= _maxNumberOfContinuationGraphElements) { throw new OutOfMemoryException($"Unable to store continuation graph element (limit is {_maxNumberOfContinuationGraphElements} entries)"); } return(locationOfFirstNewEntry); }
private long GetPlaceForNewContinuationGraphElements(int number) { var locationOfFirstNewEntry = InterlockedExtensions.AddFetch(ref _continuationGraphElementCount, number); if (locationOfFirstNewEntry >= _maxNumberOfContinuationGraphElements) { throw new OutOfMemoryException("Unable to store transitions. Try increasing the transition capacity."); } return(locationOfFirstNewEntry); }
private long GetPlaceForNewTransitionChainElements(long number) { var locationOfFirstNewEntry = InterlockedExtensions.AddFetch(ref _transitionChainElementCount, number); if (locationOfFirstNewEntry + number >= _maxNumberOfTransitions) { throw new OutOfMemoryException("Unable to store transitions. Try increasing the transition capacity."); } return(locationOfFirstNewEntry); }
/// <summary> /// Adds the <paramref name="state" /> and all of its <see cref="transitions" /> to the state graph. /// </summary> /// <param name="state">The state that should be added.</param> /// <param name="isInitial">Indicates whether the state is an initial state.</param> /// <param name="transitions">The transitions leaving the state.</param> /// <param name="transitionCount">The number of valid transitions leaving the state.</param> internal void AddStateInfo(int state, bool isInitial, TransitionCollection transitions, int transitionCount) { Assert.That(!isInitial || _initialTransitionCount == 0, "Initial transitions can only be added once."); if (isInitial) { _initialTransitionCount = transitionCount; } else { Interlocked.Increment(ref _stateCount); } Interlocked.Add(ref _transitionCount, transitionCount); // Transitions are synchronized by atomatically incrementing the offset counter var offset = InterlockedExtensions.AddFetch(ref _transitionOffset, transitionCount); if (offset + transitionCount > _transitionCapacity) { throw new OutOfMemoryException("Unable to store transitions. Try increasing the transition capacity."); } // No need to synchronize state addition, as all states are only discovered once if (!isInitial) { _stateMap[state] = new TransitionRange { StartIndex = offset, Count = transitionCount } } ; // Copy the transitions into the buffer foreach (var transition in transitions) { Assert.That(TransitionFlags.IsValid(transition->Flags), "Attempted to add an invalid transition."); MemoryBuffer.Copy((byte *)transition, _transitions + offset * TransitionSize, TransitionSize); ++offset; } }