private readonly IDictionary <ThreadJob, bool> waiting = new JCG.Dictionary <ThreadJob, bool>(IdentityEqualityComparer <ThreadJob> .Default); // only with assert

        /// <summary>
        /// Update the stalled flag status. this method will set the stalled flag to
        /// <c>true</c> iff the number of flushing
        /// <see cref="DocumentsWriterPerThread"/> is greater than the number of active
        /// <see cref="DocumentsWriterPerThread"/>. Otherwise it will reset the
        /// <see cref="DocumentsWriterStallControl"/> to healthy and release all threads
        /// waiting on <see cref="WaitIfStalled()"/>
        /// </summary>
        internal void UpdateStalled(bool stalled)
        {
            UninterruptableMonitor.Enter(this);
            try
            {
                this.stalled = stalled;
                if (stalled)
                {
                    wasStalled = true;
                }
                UninterruptableMonitor.PulseAll(this);
            }
            finally
            {
                UninterruptableMonitor.Exit(this);
            }
        }
Esempio n. 2
0
 public void Release(ThreadState state)
 {
     state.Unlock();
     UninterruptableMonitor.Enter(this);
     try
     {
         Debug.Assert(freeCount < freeList.Length);
         freeList[freeCount++] = state;
         // In case any thread is waiting, wake one of them up since we just released a thread state; notify() should be sufficient but we do
         // notifyAll defensively:
         UninterruptableMonitor.PulseAll(this);
     }
     finally
     {
         UninterruptableMonitor.Exit(this);
     }
 }
 internal void DoAfterFlush(DocumentsWriterPerThread dwpt)
 {
     UninterruptableMonitor.Enter(this);
     try
     {
         if (Debugging.AssertsEnabled)
         {
             Debugging.Assert(flushingWriters.ContainsKey(dwpt));
         }
         try
         {
             long bytes = flushingWriters[dwpt];
             flushingWriters.Remove(dwpt);
             flushBytes -= bytes;
             //perThreadPool.Recycle(dwpt); // LUCENENET: This is a no-op method in Lucene and it cannot be overridden
             if (Debugging.AssertsEnabled)
             {
                 Debugging.Assert(AssertMemory());
             }
         }
         finally
         {
             try
             {
                 UpdateStallState();
             }
             finally
             {
                 UninterruptableMonitor.PulseAll(this);
             }
         }
     }
     finally
     {
         UninterruptableMonitor.Exit(this);
     }
 }
Esempio n. 4
0
            public override void Run()
            {
                // First time through the while loop we do the merge
                // that we were started with:
                MergePolicy.OneMerge merge = this.startMerge;

                try
                {
                    if (outerInstance.IsVerbose)
                    {
                        outerInstance.Message("  merge thread: start");
                    }

                    while (true)
                    {
                        RunningMerge = merge;
                        outerInstance.DoMerge(merge);

                        // Subsequent times through the loop we do any new
                        // merge that writer says is necessary:
                        merge = tWriter.NextMerge();

                        // Notify here in case any threads were stalled;
                        // they will notice that the pending merge has
                        // been pulled and possibly resume:
                        UninterruptableMonitor.Enter(outerInstance);
                        try
                        {
                            UninterruptableMonitor.PulseAll(outerInstance);
                        }
                        finally
                        {
                            UninterruptableMonitor.Exit(outerInstance);
                        }

                        if (merge != null)
                        {
                            outerInstance.UpdateMergeThreads();
                            if (outerInstance.IsVerbose)
                            {
                                outerInstance.Message("  merge thread: do another merge " + tWriter.SegString(merge.Segments));
                            }
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (outerInstance.IsVerbose)
                    {
                        outerInstance.Message("  merge thread: done");
                    }
                }
                catch (Exception exc) when(exc.IsThrowable())
                {
                    // Ignore the exception if it was due to abort:
                    if (!(exc is MergePolicy.MergeAbortedException))
                    {
                        //System.out.println(Thread.currentThread().getName() + ": CMS: exc");
                        //exc.printStackTrace(System.out);
                        if (!outerInstance.suppressExceptions)
                        {
                            // suppressExceptions is normally only set during
                            // testing.
                            outerInstance.HandleMergeException(exc);
                        }
                    }
                }
                finally
                {
                    done = true;
                    UninterruptableMonitor.Enter(outerInstance);
                    try
                    {
                        outerInstance.UpdateMergeThreads();
                        UninterruptableMonitor.PulseAll(outerInstance);
                    }
                    finally
                    {
                        UninterruptableMonitor.Exit(outerInstance);
                    }
                }
            }