public bool Poll(out T di, StCancelArgs cargs) { m.WaitOne(); try { if (buffer.Count > 0) { di = buffer.Dequeue(); nonFull.Pulse(); return(true); } while (true) { int lastTime = Environment.TickCount; nonEmpty.Wait(cargs); if (buffer.Count > 0) { di = buffer.Dequeue(); nonFull.Pulse(); return(true); } if (!cargs.AdjustTimeout(ref lastTime)) { di = default(T); return(false); } } } finally { m.Exit(); } }
public bool Offer(T data, StCancelArgs cargs) { m.WaitOne(); try { if (buffer.Count < capacity) { buffer.Enqueue(data); nonEmpty.Pulse(); return(true); } while (true) { int lastTime = Environment.TickCount; nonFull.Wait(cargs); if (buffer.Count < capacity) { buffer.Enqueue(data); nonEmpty.Pulse(); return(true); } if (!cargs.AdjustTimeout(ref lastTime)) { return(false); } } } finally { m.Exit(); } }