diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2023-05-28 20:48:07 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2023-06-14 22:17:17 +0200 |
commit | be323e65108f4c1d57312a4d26a6a24d3a380c75 (patch) | |
tree | 2ddc81ef079f3d42fb4d4780a5fd1cf0d27ef7b5 /src/storage.h | |
parent | 15ad6ae7bd64d8d7319d75dbbb0827addd22fef2 (diff) |
Storage: wait for scheduled watch callbacks
Diffstat (limited to 'src/storage.h')
-rw-r--r-- | src/storage.h | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/storage.h b/src/storage.h index 30e4213..c6b5ed2 100644 --- a/src/storage.h +++ b/src/storage.h @@ -45,6 +45,24 @@ public: virtual void storeKey(const Digest &, const vector<uint8_t> &) = 0; }; +class StorageWatchCallback +{ +public: + StorageWatchCallback(int id, const function<void(UUID, const Digest &)> callback): + id(id), callback(callback) {} + + void schedule(UUID, const Digest &); + void run(); + + const int id; + +private: + const function<void(UUID, const Digest &)> callback; + + std::recursive_mutex runMutex; + optional<tuple<UUID, Digest>> scheduled; +}; + class FilesystemStorage : public StorageBackend { public: @@ -85,7 +103,7 @@ private: int inotify = -1; int inotifyWakeup = -1; int nextWatcherId = 1; - unordered_multimap<UUID, tuple<int, function<void(UUID id, const Digest &)>>> watchers; + unordered_multimap<UUID, shared_ptr<StorageWatchCallback>> watchers; unordered_map<int, UUID> watchMap; }; @@ -117,7 +135,7 @@ private: mutex watcherLock; int nextWatcherId = 1; - unordered_multimap<UUID, tuple<int, function<void(UUID id, const Digest &)>>> watchers; + unordered_multimap<UUID, shared_ptr<StorageWatchCallback>> watchers; }; class ChainStorage : public StorageBackend |