From 3f9ad8e104887bac46e778b0ee4c9ea298a488aa Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 27 Feb 2014 18:04:24 +0100 Subject: db/update/Service: allocate UpdateWalk dynamically --- src/db/update/Service.cxx | 28 +++++++++++++++++++++------- src/db/update/Service.hxx | 6 ++++-- src/db/update/UpdateSong.cxx | 2 +- src/db/update/Walk.cxx | 3 ++- src/db/update/Walk.hxx | 8 -------- 5 files changed, 28 insertions(+), 19 deletions(-) (limited to 'src/db/update') diff --git a/src/db/update/Service.cxx b/src/db/update/Service.cxx index 112d97760..0c93ce36e 100644 --- a/src/db/update/Service.cxx +++ b/src/db/update/Service.cxx @@ -19,6 +19,7 @@ #include "config.h" #include "Service.hxx" +#include "Walk.hxx" #include "UpdateDomain.hxx" #include "db/DatabaseListener.hxx" #include "db/plugins/simple/SimpleDatabasePlugin.hxx" @@ -40,10 +41,12 @@ UpdateService::UpdateService(EventLoop &_loop, SimpleDatabase &_db, Storage &_storage, DatabaseListener &_listener) - :DeferredMonitor(_loop), db(_db), listener(_listener), + :DeferredMonitor(_loop), + db(_db), storage(_storage), + listener(_listener), progress(UPDATE_PROGRESS_IDLE), update_task_id(0), - walk(_loop, _listener, _storage) + walk(nullptr) { } @@ -53,6 +56,8 @@ UpdateService::~UpdateService() if (update_thread.IsDefined()) update_thread.Join(); + + delete walk; } void @@ -61,12 +66,16 @@ UpdateService::CancelAllAsync() assert(GetEventLoop().IsInsideOrNull()); queue.Clear(); - walk.Cancel(); + + if (walk != nullptr) + walk->Cancel(); } inline void UpdateService::Task() { + assert(walk != nullptr); + if (!next.path_utf8.empty()) FormatDebug(update_domain, "starting: %s", next.path_utf8.c_str()); @@ -75,8 +84,8 @@ UpdateService::Task() SetThreadIdlePriority(); - modified = walk.Walk(*db.GetRoot(), next.path_utf8.c_str(), - next.discard); + modified = walk->Walk(*db.GetRoot(), next.path_utf8.c_str(), + next.discard); if (modified || !db.FileExists()) { Error error; @@ -105,13 +114,13 @@ void UpdateService::StartThread(UpdateQueueItem &&i) { assert(GetEventLoop().IsInsideOrNull()); + assert(walk == nullptr); progress = UPDATE_PROGRESS_RUNNING; modified = false; next = std::move(i); - - walk.Prepare(); + walk = new UpdateWalk(GetEventLoop(), listener, storage); Error error; if (!update_thread.Start(Task, this, error)) @@ -160,8 +169,13 @@ UpdateService::RunDeferred() { assert(progress == UPDATE_PROGRESS_DONE); assert(next.IsDefined()); + assert(walk != nullptr); update_thread.Join(); + + delete walk; + walk = nullptr; + next = UpdateQueueItem(); idle_add(IDLE_UPDATE); diff --git a/src/db/update/Service.hxx b/src/db/update/Service.hxx index ebdda7bd1..e42a0fa5a 100644 --- a/src/db/update/Service.hxx +++ b/src/db/update/Service.hxx @@ -22,12 +22,13 @@ #include "check.h" #include "Queue.hxx" -#include "Walk.hxx" #include "event/DeferredMonitor.hxx" #include "thread/Thread.hxx" class SimpleDatabase; class DatabaseListener; +class UpdateWalk; +class Storage; /** * This class manages the update queue and runs the update thread. @@ -40,6 +41,7 @@ class UpdateService final : DeferredMonitor { }; SimpleDatabase &db; + Storage &storage; DatabaseListener &listener; @@ -57,7 +59,7 @@ class UpdateService final : DeferredMonitor { UpdateQueueItem next; - UpdateWalk walk; + UpdateWalk *walk; public: UpdateService(EventLoop &_loop, SimpleDatabase &_db, diff --git a/src/db/update/UpdateSong.cxx b/src/db/update/UpdateSong.cxx index 6b24276fd..005bf8992 100644 --- a/src/db/update/UpdateSong.cxx +++ b/src/db/update/UpdateSong.cxx @@ -18,7 +18,7 @@ */ #include "config.h" /* must be first for large file support */ -#include "Service.hxx" +#include "Walk.hxx" #include "UpdateIO.hxx" #include "UpdateDomain.hxx" #include "db/DatabaseLock.hxx" diff --git a/src/db/update/Walk.cxx b/src/db/update/Walk.cxx index db05b1823..201030f25 100644 --- a/src/db/update/Walk.cxx +++ b/src/db/update/Walk.cxx @@ -51,7 +51,8 @@ UpdateWalk::UpdateWalk(EventLoop &_loop, DatabaseListener &_listener, Storage &_storage) - :storage(_storage), + :cancel(false), + storage(_storage), editor(_loop, _listener) { #ifndef WIN32 diff --git a/src/db/update/Walk.hxx b/src/db/update/Walk.hxx index 353f6f3ed..cce276ab0 100644 --- a/src/db/update/Walk.hxx +++ b/src/db/update/Walk.hxx @@ -71,14 +71,6 @@ public: cancel = true; } - /** - * Call from the main thread before starting the update - * thread. - */ - void Prepare() { - cancel = false; - } - /** * Returns true if the database was modified. */ -- cgit v1.2.3