Mercurial > minori
diff include/library/library.h @ 409:8d06825d96d1
library: refresh in a separate thread
this is fugly but it works
| author | Paper <paper@tflc.us> |
|---|---|
| date | Thu, 02 Apr 2026 00:18:56 -0400 |
| parents | e561b7542b7b |
| children | eb554255ea5f |
line wrap: on
line diff
--- a/include/library/library.h Wed Jan 21 11:35:32 2026 -0500 +++ b/include/library/library.h Thu Apr 02 00:18:56 2026 -0400 @@ -7,6 +7,8 @@ #include <filesystem> #include <optional> #include <unordered_map> +#include <thread> +#include <mutex> namespace Library { @@ -26,16 +28,27 @@ void Refresh(); void Refresh(int id); - // Anime episodes. Indexed as `folders[id][episode]' - std::unordered_map<int, std::unordered_map<int, std::filesystem::path>> items; + std::optional<std::filesystem::path> GetAnimeEpisodePath(int anime, int episode); private: void Refresh(std::optional<int> find_id); + /* refresh_thread entry point */ + void RefreshThread(); Filesystem::PathMap<std::unique_ptr<Filesystem::IWatcher>> watchers_; - /* ID we're looking for */ + /* ID we're looking for (This is terrible, but other ways are also terrible in their own unique ways) */ std::optional<int> find_id_; + + /* Anime episodes. Indexed as `folders[id][episode]' */ + std::unordered_map<int, std::unordered_map<int, std::filesystem::path>> items; + std::recursive_mutex items_mutex_; + + /* Thread that runs the refreshing. + * When Refresh() is called, if this is a valid thread, then it will be + * join()'d. This stinks, and a better method would be to have the + * thread running in the background waiting on a queue. Oh well. */ + std::thread refresh_thread_; }; extern Database db;
