public object Allocate() { Interlocked.Increment(ref AllocCount); #if (NET_2_0) Core.Utils.SpinWait spin = new Core.Utils.SpinWait(); #else System.Threading.SpinWait spin = new System.Threading.SpinWait(); #endif while (Interlocked.Increment(ref _allocatorNumber) != 1) { Interlocked.Decrement(ref _allocatorNumber); spin.SpinOnce(); } object obj; var succ = _pool.TryDequeue(out obj); Interlocked.Decrement(ref _allocatorNumber); if (!succ || obj == null) { Interlocked.Increment(ref NewCount); obj = _factory.MakeObject(); } _factory.ActivateObject(obj); return(obj); }
public virtual T Take() { T obj; if (_pools.Count == 0) { obj = _factory.CreateObject(true); } else { obj = _pools[0]; _factory.ActivateObject(obj); _pools.RemoveAt(0); } _activeCount++; return(obj); }
public T Take() { T t; if (pools.Count == 0) { t = factory.CreateObject(true); } else { t = pools[0]; factory.ActivateObject(t); pools.RemoveAt(0); } activeNum++; return(t); }