diff --git a/src/core/library/Indexer.cpp b/src/core/library/Indexer.cpp index e345128e6..68e71804e 100644 --- a/src/core/library/Indexer.cpp +++ b/src/core/library/Indexer.cpp @@ -102,7 +102,8 @@ Indexer::Indexer(const std::string& libraryPath, const std::string& dbFilename) , tracksScanned(0) , exit(false) , state(StateIdle) -, prefs(Preferences::ForComponent(prefs::components::Settings)) { +, prefs(Preferences::ForComponent(prefs::components::Settings)) +, readSemaphore(prefs->GetInt(prefs::keys::MaxTagReadThreads, MAX_THREADS)) { this->metadataReaders = PluginFactory::Instance() .QueryInterface("GetMetadataReader"); @@ -395,6 +396,10 @@ void Indexer::ReadMetadataFromFile( } this->IncrementTracksScanned(); + +#ifdef MULTI_THREADED_INDEXER + this->readSemaphore.post(); +#endif } inline void Indexer::IncrementTracksScanned(size_t delta) { @@ -444,6 +449,8 @@ void Indexer::SyncDirectory( } else { if (io) { + this->readSemaphore.wait(); + io->post(boost::bind( &Indexer::ReadMetadataFromFile, this, diff --git a/src/core/library/Indexer.h b/src/core/library/Indexer.h index 136a6a514..016069fe3 100644 --- a/src/core/library/Indexer.h +++ b/src/core/library/Indexer.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #include @@ -156,6 +157,7 @@ namespace musik { namespace core { std::shared_ptr trackTransaction; std::vector paths; std::shared_ptr currentSource; + boost::interprocess::interprocess_semaphore readSemaphore; }; typedef std::shared_ptr IndexerPtr;