diff options
Diffstat (limited to 'src/storage.h')
-rw-r--r-- | src/storage.h | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/src/storage.h b/src/storage.h index b8d769c..7ed8cf6 100644 --- a/src/storage.h +++ b/src/storage.h @@ -39,7 +39,8 @@ public: virtual vector<tuple<UUID, Digest>> headRefs(UUID type) const = 0; virtual UUID storeHead(UUID type, const Digest & dgst) = 0; virtual bool replaceHead(UUID type, UUID id, const Digest & old, const Digest & dgst) = 0; - virtual void watchHead(UUID type, const function<void(UUID id, const Digest &)> &) = 0; + virtual int watchHead(UUID type, const function<void(UUID id, const Digest &)> &) = 0; + virtual void unwatchHead(UUID type, int watchId) = 0; virtual optional<vector<uint8_t>> loadKey(const Digest &) const = 0; virtual void storeKey(const Digest &, const vector<uint8_t> &) = 0; @@ -60,7 +61,8 @@ public: virtual vector<tuple<UUID, Digest>> headRefs(UUID type) const override; virtual UUID storeHead(UUID type, const Digest & dgst) override; virtual bool replaceHead(UUID type, UUID id, const Digest & old, const Digest & dgst) override; - virtual void watchHead(UUID type, const function<void(UUID id, const Digest &)> &) override; + virtual int watchHead(UUID type, const function<void(UUID id, const Digest &)> &) override; + virtual void unwatchHead(UUID type, int watchId) override; virtual optional<vector<uint8_t>> loadKey(const Digest &) const override; virtual void storeKey(const Digest &, const vector<uint8_t> &) override; @@ -83,7 +85,8 @@ private: std::thread watcherThread; int inotify = -1; int inotifyWakeup = -1; - unordered_multimap<UUID, function<void(UUID id, const Digest &)>> watchers; + int nextWatcherId = 1; + unordered_multimap<UUID, tuple<int, function<void(UUID id, const Digest &)>>> watchers; unordered_map<int, UUID> watchMap; }; @@ -102,7 +105,8 @@ public: virtual vector<tuple<UUID, Digest>> headRefs(UUID type) const override; virtual UUID storeHead(UUID type, const Digest & dgst) override; virtual bool replaceHead(UUID type, UUID id, const Digest & old, const Digest & dgst) override; - virtual void watchHead(UUID type, const function<void(UUID id, const Digest &)> &) override; + virtual int watchHead(UUID type, const function<void(UUID id, const Digest &)> &) override; + virtual void unwatchHead(UUID type, int watchId) override; virtual optional<vector<uint8_t>> loadKey(const Digest &) const override; virtual void storeKey(const Digest &, const vector<uint8_t> &) override; @@ -113,7 +117,8 @@ private: unordered_map<Digest, vector<uint8_t>> keys; mutex watcherLock; - unordered_multimap<UUID, function<void(UUID id, const Digest &)>> watchers; + int nextWatcherId = 1; + unordered_multimap<UUID, tuple<int, function<void(UUID id, const Digest &)>>> watchers; }; class ChainStorage : public StorageBackend @@ -134,7 +139,8 @@ public: virtual vector<tuple<UUID, Digest>> headRefs(UUID type) const override; virtual UUID storeHead(UUID type, const Digest & dgst) override; virtual bool replaceHead(UUID type, UUID id, const Digest & old, const Digest & dgst) override; - virtual void watchHead(UUID type, const function<void(UUID id, const Digest &)> &) override; + virtual int watchHead(UUID type, const function<void(UUID id, const Digest &)> &) override; + virtual void unwatchHead(UUID type, int watchId) override; virtual optional<vector<uint8_t>> loadKey(const Digest &) const override; virtual void storeKey(const Digest &, const vector<uint8_t> &) override; @@ -142,6 +148,10 @@ public: private: shared_ptr<StorageBackend> storage; unique_ptr<ChainStorage> parent; + + mutex watcherLock; + int nextWatcherId = 1; + unordered_map<int, tuple<int, int>> watchers; }; struct PartialStorage::Priv |