bool ConcurrentMergeScheduler::anyUnhandledExceptions()
 {
     if (!allInstances)
         boost::throw_exception(RuntimeException(L"setTestMode() was not called"));
     SyncLock instancesLock(&allInstances);
     for (Collection<ConcurrentMergeSchedulerPtr>::iterator instance = allInstances.begin(); instance != allInstances.end(); ++instance)
         (*instance)->sync();
     bool v = anyExceptions;
     anyExceptions = false;
     return v;
 }
void ConcurrentMergeScheduler::addMyself() {
    SyncLock instancesLock(&allInstances);
    int32_t size = allInstances.size();
    int32_t upto = 0;
    for (int32_t i = 0; i < size; ++i) {
        ConcurrentMergeSchedulerPtr other(allInstances[i]);
        if (!(other->closed && other->mergeThreadCount() == 0)) {
            // Keep this one for now: it still has threads or may spawn new threads
            allInstances[upto++] = other;
        }

        allInstances.remove(allInstances.begin() + upto, allInstances.end());
        allInstances.add(shared_from_this());
    }
}
 DocIdSetIteratorPtr FieldCacheDocIdSet::iterator()
 {
     // Synchronization needed because deleted docs BitVector can change after call to hasDeletions until 
     // TermDocs creation.  We only use an iterator with termDocs, when this was requested (eg. range 
     // contains 0) and the index has deletions
     TermDocsPtr termDocs;
     {
         SyncLock instancesLock(reader);
         termDocs = isCacheable() ? TermDocsPtr() : reader->termDocs(TermPtr());
     }
     if (termDocs)
     {
         // a DocIdSetIterator using TermDocs to iterate valid docIds
         return newLucene<FieldDocIdSetIteratorTermDocs>(shared_from_this(), termDocs);
     }
     else
     {
         // a DocIdSetIterator generating docIds by incrementing a variable - this one can be used if there 
         // are no deletions are on the index
         return newLucene<FieldDocIdSetIteratorIncrement>(shared_from_this());
     }
 }
 void ConcurrentMergeScheduler::clearUnhandledExceptions()
 {
     SyncLock instancesLock(&allInstances);
     anyExceptions = false;
 }