/// <summary> /// Set the waiter /// </summary> private void FreeWaiter() { if (Waiter != null) { Waiter.Set(); Waiter.Dispose(); Waiter = null; } }
public void Dispose() { if (!_disposed) { Waiter?.Dispose(); Socket?.Dispose(); _disposed = true; GC.SuppressFinalize(this); } }
public void Dispose() { if (Interlocked.Exchange(ref _disposeSignaled, 1) != 0) { return; } Waiter.Dispose(); Waiter = null; Responder.Dispose(); Responder = null; }
/// <summary> /// wait for this task to finish /// </summary> public void Wait() { if (IsCompleted) { return; } var w = new Waiter(); OnComplete(w); #if ECHOES w.ev.WaitOne(); #elseif COOPER lock (w.o) { while (!w.done) { w.o.wait(); } } #else w.ev.Wait(); #endif w.Dispose(); }
public T[] CheckOut(int size) { bool successAlt = false; this.queuesLock.Enter(ref successAlt); Debug.Assert(successAlt); // first look for a free buffer in the queue if (this.buffers.Count > 0) { // Return a buffer from the queue of checked-in buffers. T[] ret = this.buffers.Dequeue(); this.queuesLock.Exit(); return(ret); } else { this.queuesLock.Exit(); } // if free capacity, consider allocation. if (this.numAllocated < this.capacity) { // grab a ticket, and if it is valid (below capacity) allocate! var ticketNumber = Interlocked.Increment(ref this.numAllocated); if (ticketNumber < this.capacity) { return(new T[bufferLength]); } } // We have allocated all buffers, so it's time to access the queues. bool success = false; this.queuesLock.Enter(ref success); Debug.Assert(success); if (this.buffers.Count > 0) { // Return a buffer from the queue of checked-in buffers. T[] ret = this.buffers.Dequeue(); this.queuesLock.Exit(); return(ret); } else { // Enqueue a waiter for a checked-in buffer. Waiter myWaiter = new Waiter(); this.waiters.Enqueue(myWaiter); this.queuesLock.Exit(); // Wait until my waiter is signalled (after its buffer has been set), and return that buffer. myWaiter.Event.Wait(); Debug.Assert(myWaiter.Buffer != null); Debug.Assert(myWaiter.Buffer.Length == this.bufferLength); T[] ret = myWaiter.Buffer; myWaiter.Dispose(); return(ret); } }