mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 11:10:52 +00:00
Make some of the Indexer's internals easily configurable.
This commit is contained in:
parent
3c2a06c9d3
commit
9433553db1
@ -58,7 +58,6 @@
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#define MULTI_THREADED_INDEXER 1
|
||||
#define STRESS_TEST_DB 0
|
||||
|
||||
static const std::string TAG = "Indexer";
|
||||
@ -66,9 +65,9 @@ static const size_t TRANSACTION_INTERVAL = 300;
|
||||
static FILE* logFile = nullptr;
|
||||
|
||||
#ifdef __arm__
|
||||
static const int MAX_THREADS = 2;
|
||||
static const int DEFAULT_MAX_THREADS = 2;
|
||||
#else
|
||||
static const int MAX_THREADS = 4;
|
||||
static const int DEFAULT_MAX_THREADS = 4;
|
||||
#endif
|
||||
|
||||
using namespace musik::core;
|
||||
@ -110,7 +109,7 @@ Indexer::Indexer(const std::string& libraryPath, const std::string& dbFilename)
|
||||
, totalUrisScanned(0)
|
||||
, state(StateStopped)
|
||||
, prefs(Preferences::ForComponent(prefs::components::Settings))
|
||||
, readSemaphore(prefs->GetInt(prefs::keys::MaxTagReadThreads, MAX_THREADS)) {
|
||||
, readSemaphore(prefs->GetInt(prefs::keys::IndexerThreadCount, DEFAULT_MAX_THREADS)) {
|
||||
if (prefs->GetBool(prefs::keys::IndexerLogEnabled, false) && !logFile) {
|
||||
openLogFile();
|
||||
}
|
||||
@ -414,10 +413,7 @@ void Indexer::ReadMetadataFromFile(
|
||||
}
|
||||
|
||||
this->IncrementTracksScanned();
|
||||
|
||||
#ifdef MULTI_THREADED_INDEXER
|
||||
this->readSemaphore.post();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void Indexer::IncrementTracksScanned(int delta) {
|
||||
@ -426,6 +422,7 @@ inline void Indexer::IncrementTracksScanned(int delta) {
|
||||
this->incrementalUrisScanned.fetch_add(delta);
|
||||
this->totalUrisScanned.fetch_add(delta);
|
||||
|
||||
int interval = prefs->GetInt(prefs::keys::IndexerTransactionInterval, TRANSACTION_INTERVAL);
|
||||
if (this->incrementalUrisScanned > TRANSACTION_INTERVAL) {
|
||||
this->trackTransaction->CommitAndRestart();
|
||||
this->Progress(this->totalUrisScanned);
|
||||
@ -595,26 +592,27 @@ void Indexer::ThreadLoop() {
|
||||
this->dbConnection.Open(this->dbFilename.c_str(), 0);
|
||||
this->trackTransaction.reset(new db::ScopedTransaction(this->dbConnection));
|
||||
|
||||
#if MULTI_THREADED_INDEXER
|
||||
boost::asio::io_service io;
|
||||
boost::thread_group threadPool;
|
||||
boost::asio::io_service::work work(io);
|
||||
int threadCount = prefs->GetInt(prefs::keys::IndexerThreadCount, DEFAULT_MAX_THREADS);
|
||||
if (threadCount > 1) {
|
||||
boost::asio::io_service io;
|
||||
boost::thread_group threadPool;
|
||||
boost::asio::io_service::work work(io);
|
||||
|
||||
/* initialize the thread pool -- we'll use this to index tracks in parallel. */
|
||||
int threadCount = prefs->GetInt(prefs::keys::MaxTagReadThreads, MAX_THREADS);
|
||||
for (int i = 0; i < threadCount; i++) {
|
||||
threadPool.create_thread(boost::bind(&boost::asio::io_service::run, &io));
|
||||
/* initialize the thread pool -- we'll use this to index tracks in parallel. */
|
||||
for (int i = 0; i < threadCount; i++) {
|
||||
threadPool.create_thread(boost::bind(&boost::asio::io_service::run, &io));
|
||||
}
|
||||
|
||||
this->Synchronize(context, &io);
|
||||
|
||||
/* done with sync, remove all the threads in the pool to free resources. they'll
|
||||
be re-created later if we index again. */
|
||||
io.stop();
|
||||
threadPool.join_all();
|
||||
}
|
||||
else {
|
||||
this->Synchronize(context, nullptr);
|
||||
}
|
||||
|
||||
this->Synchronize(context, &io);
|
||||
|
||||
/* done with sync, remove all the threads in the pool to free resources. they'll
|
||||
be re-created later if we index again. */
|
||||
io.stop();
|
||||
threadPool.join_all();
|
||||
#else
|
||||
this->Synchronize(context, nullptr);
|
||||
#endif
|
||||
|
||||
this->FinalizeSync(context);
|
||||
|
||||
|
@ -44,7 +44,6 @@ namespace musik { namespace core { namespace prefs {
|
||||
const std::string components::Session = "session";
|
||||
|
||||
const std::string keys::AutoSyncIntervalMillis = "AutoSyncIntervalMillis";
|
||||
const std::string keys::MaxTagReadThreads = "MaxTagReadThreads";
|
||||
const std::string keys::RemoveMissingFiles = "RemoveMissingFiles";
|
||||
const std::string keys::SyncOnStartup = "SyncOnStartup";
|
||||
const std::string keys::Volume = "Volume";
|
||||
@ -54,6 +53,8 @@ namespace musik { namespace core { namespace prefs {
|
||||
const std::string keys::Transport = "Transport";
|
||||
const std::string keys::Locale = "Locale";
|
||||
const std::string keys::IndexerLogEnabled = "IndexerLogEnabled";
|
||||
const std::string keys::IndexerThreadCount = "IndexerThreadCount";
|
||||
const std::string keys::IndexerTransactionInterval = "IndexerTransactionInterval";
|
||||
const std::string keys::ReplayGainMode = "ReplayGainMode";
|
||||
const std::string keys::PreampDecibels = "PreampDecibels";
|
||||
const std::string keys::SaveSessionOnExit = "SaveSessionOnExit";
|
||||
|
@ -48,7 +48,6 @@ namespace musik { namespace core { namespace prefs {
|
||||
|
||||
namespace keys {
|
||||
extern const std::string AutoSyncIntervalMillis;
|
||||
extern const std::string MaxTagReadThreads;
|
||||
extern const std::string RemoveMissingFiles;
|
||||
extern const std::string SyncOnStartup;
|
||||
extern const std::string Volume;
|
||||
@ -58,6 +57,9 @@ namespace musik { namespace core { namespace prefs {
|
||||
extern const std::string Transport;
|
||||
extern const std::string Locale;
|
||||
extern const std::string IndexerLogEnabled;
|
||||
extern const std::string IndexerThreadCount;
|
||||
extern const std::string IndexerTransactionInterval;
|
||||
|
||||
extern const std::string ReplayGainMode;
|
||||
extern const std::string PreampDecibels;
|
||||
extern const std::string SaveSessionOnExit;
|
||||
|
@ -102,6 +102,12 @@ using namespace std::placeholders;
|
||||
checkbox->SetText(caption); \
|
||||
checkbox->CheckChanged.connect(this, &SettingsLayout::OnCheckboxChanged);
|
||||
|
||||
#ifdef __arm__
|
||||
static const int DEFAULT_MAX_INDEXER_THREADS = 2;
|
||||
#else
|
||||
static const int DEFAULT_MAX_INDEXER_THREADS = 4;
|
||||
#endif
|
||||
|
||||
using EntryPtr = IScrollAdapter::EntryPtr;
|
||||
|
||||
static const std::string arrow = "> ";
|
||||
@ -121,6 +127,9 @@ static inline std::shared_ptr<ISchema> AdvancedSettingsSchema() {
|
||||
schema->AddBool(cube::prefs::keys::DisableWindowTitleUpdates, false);
|
||||
schema->AddString(cube::prefs::keys::RatingPositiveChar, kFilledStar.c_str());
|
||||
schema->AddString(cube::prefs::keys::RatingNegativeChar, kEmptyStar.c_str());
|
||||
schema->AddBool(core::prefs::keys::IndexerLogEnabled, false);
|
||||
schema->AddInt(core::prefs::keys::IndexerThreadCount, DEFAULT_MAX_INDEXER_THREADS);
|
||||
schema->AddInt(core::prefs::keys::IndexerTransactionInterval, 300);
|
||||
schema->AddString(core::prefs::keys::AuddioApiToken, "");
|
||||
return schema;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user