public void Renew() { if (_perCorePropertiesCache.TryPull(out _cachedSorts) == false) { _cachedSorts = new CachedSort[CachedSortsSize]; // size is fixed and used in GetPropertiesHashedIndex } }
public IDisposable AllocateOperationContext(out T context) { _cts.Token.ThrowIfCancellationRequested(); while (_perCoreCache.TryPull(out context)) { if (context.InUse.Raise() == false) continue; // This what ensures that we work correctly with races from other threads // if there is a context switch at the wrong time context.Renew(); return new ReturnRequestContext { Parent = this, Context = context }; } if (TryGetFromStack(_globalStack, out context)) { return new ReturnRequestContext { Parent = this, Context = context }; } // no choice, got to create it context = CreateContext(); context.PoolGeneration = _generation; return new ReturnRequestContext { Parent = this, Context = context };