public override void Write(XmlNodeType nodeType, QName name, string value) { lock (this) { Debug.Assert(ReadEndPos <= WritePos && WritePos <= ReadStartPos + Buffer.Length); if (WritePos == ReadStartPos + Buffer.Length) { if (WritePos == ReadEndPos) { ExpandBuffer(); } else { Monitor.Wait(this); } } Debug.Assert(WritePos < ReadStartPos + Buffer.Length); XmlToken.Set(ref Buffer[WritePos & Mask], nodeType, name, value); WritePos++; if (ReadStartPos + Buffer.Length <= WritePos) { // This "if" is some heuristics, it may wrk or may not: // To minimize task switching we wakeup reader ony if we wrote enouph tokens. // So if reader already waits, let it sleep before we fill up the buffer. Monitor.Pulse(this); } } }
public virtual void Write(XmlNodeType nodeType, QName name, string value) { Debug.Assert(WritePos <= Buffer.Length); if (WritePos == Buffer.Length) { var temp = new XmlToken[Buffer.Length * 2]; Buffer.CopyTo(temp, 0); Buffer = temp; } Debug.Assert(WritePos < Buffer.Length); XmlToken.Set(ref Buffer[WritePos], nodeType, name, value); WritePos++; }