예제 #1
0
 public void Initialize(ConcurrentAsyncBlockingQueue <T> queue)
 {
     if (_token != 0)
     {
         throw new InvalidOperationException();
     }
     _token = AllocateToken();
     _queue = queue;
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
            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);
            }