/// <summary>Does the synchronized work to finish/flush the /// inverted document. /// </summary> private void FinishDocument(DocumentsWriterThreadState perThread, DocWriter docWriter) { if (DoBalanceRAM()) // Must call this w/o holding synchronized(this) else // we'll hit deadlock: BalanceRAM(); lock (this) { System.Diagnostics.Debug.Assert(docWriter == null || docWriter.docID == perThread.docState.docID); if (aborting) { // We are currently aborting, and another thread is // waiting for me to become idle. We just forcefully // idle this threadState; it will be fully reset by // abort() if (docWriter != null) try { docWriter.Abort(); } catch (System.Exception) { } perThread.isIdle = true; System.Threading.Monitor.PulseAll(this); return ; } bool doPause; if (docWriter != null) doPause = waitQueue.Add(docWriter); else { skipDocWriter.docID = perThread.docState.docID; doPause = waitQueue.Add(skipDocWriter); } if (doPause) WaitForWaitQueue(); if (bufferIsFull && !flushPending) { flushPending = true; perThread.doFlushAfter = true; } perThread.isIdle = true; System.Threading.Monitor.PulseAll(this); } }