summaryrefslogtreecommitdiff
path: root/src/database/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/database/include')
-rw-r--r--src/database/include/database.hpp6
-rw-r--r--src/database/include/db_task.hpp25
-rw-r--r--src/database/include/env_esp.hpp5
3 files changed, 10 insertions, 26 deletions
diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp
index da0ed083..ce2ca9fe 100644
--- a/src/database/include/database.hpp
+++ b/src/database/include/database.hpp
@@ -19,6 +19,7 @@
#include "result.hpp"
#include "song.hpp"
#include "tag_parser.hpp"
+#include "tasks.hpp"
namespace database {
@@ -90,6 +91,8 @@ class Database {
leveldb::DB* db_;
leveldb::Cache* cache_;
+ std::shared_ptr<tasks::Worker> worker_task_;
+
// Not owned.
IFileGatherer* file_gatherer_;
ITagParser* tag_parser_;
@@ -97,7 +100,8 @@ class Database {
Database(leveldb::DB* db,
leveldb::Cache* cache,
IFileGatherer* file_gatherer,
- ITagParser* tag_parser);
+ ITagParser* tag_parser,
+ std::shared_ptr<tasks::Worker> worker);
auto dbMintNewSongId() -> SongId;
auto dbEntomb(SongId song, uint64_t hash) -> void;
diff --git a/src/database/include/db_task.hpp b/src/database/include/db_task.hpp
deleted file mode 100644
index 39f932b0..00000000
--- a/src/database/include/db_task.hpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#pragma once
-
-#include <functional>
-#include <future>
-#include <memory>
-
-namespace database {
-
-auto StartDbTask() -> bool;
-auto QuitDbTask() -> void;
-
-auto SendToDbTask(std::function<void(void)> fn) -> void;
-
-template <typename T>
-auto RunOnDbTask(std::function<T(void)> fn) -> std::future<T> {
- std::shared_ptr<std::promise<T>> promise =
- std::make_shared<std::promise<T>>();
- SendToDbTask([=]() { promise->set_value(std::invoke(fn)); });
- return promise->get_future();
-}
-
-template <>
-auto RunOnDbTask(std::function<void(void)> fn) -> std::future<void>;
-
-} // namespace database
diff --git a/src/database/include/env_esp.hpp b/src/database/include/env_esp.hpp
index cf5a20e1..6a415ce6 100644
--- a/src/database/include/env_esp.hpp
+++ b/src/database/include/env_esp.hpp
@@ -1,5 +1,6 @@
#pragma once
+#include <memory>
#include <mutex>
#include <set>
#include <string>
@@ -7,8 +8,12 @@
#include "leveldb/env.h"
#include "leveldb/status.h"
+#include "tasks.hpp"
+
namespace leveldb {
+extern std::weak_ptr<tasks::Worker> sBackgroundThread;
+
// Tracks the files locked by EspEnv::LockFile().
//
// We maintain a separate set instead of relying on fcntl(F_SETLK) because