public void Initialize(ConcurrentAsyncBlockingQueue <T> queue) { if (_token != 0) { throw new InvalidOperationException(); } _token = AllocateToken(); _queue = queue; }
private void Dispose() { if (_token == 0) { throw new ObjectDisposedException(this.GetType().Name); } _queue = null; _token = 0; _continuation = null; _state = null; this._result = default(T); //put back to pool lock (_pool){ _pool.Push(this); } }
public static AsyncBlockingQueueTakeTaskSource Request(ConcurrentAsyncBlockingQueue <T> queue) { AsyncBlockingQueueTakeTaskSource source = null; lock (_pool){ if (_pool.Count == 0) { source = new AsyncBlockingQueueTakeTaskSource(); } else { source = _pool.Pop(); } } source.Initialize(queue); return(source); }