diff options
author | George Hazan <ghazan@miranda.im> | 2022-11-30 17:48:47 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2022-11-30 17:48:47 +0300 |
commit | 0ece30dc7c0e34b4c5911969b8fa99c33c6d023c (patch) | |
tree | 671325d3fec09b999411e4e3ab84ef8259261818 /protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h | |
parent | 46c53ffc6809c67e4607e99951a2846c382b63b2 (diff) |
Telegram: update for TDLIB
Diffstat (limited to 'protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h')
-rw-r--r-- | protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h b/protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h index 8d94d79673..5663bcdfff 100644 --- a/protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h +++ b/protocols/Telegram/tdlib/td/tddb/td/db/TsSeqKeyValue.h @@ -1,5 +1,5 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -8,6 +8,7 @@ #include "td/db/SeqKeyValue.h" +#include "td/utils/HashTableUtils.h" #include "td/utils/port/RwMutex.h" #include "td/utils/Slice.h" @@ -15,6 +16,7 @@ #include <utility> namespace td { + class TsSeqKeyValue { public: using SeqNo = SeqKeyValue::SeqNo; @@ -32,30 +34,42 @@ class TsSeqKeyValue { auto lock = rw_mutex_.lock_write().move_as_ok(); return kv_.set(key, value); } + std::pair<SeqNo, RwMutex::WriteLock> set_and_lock(Slice key, Slice value) { auto lock = rw_mutex_.lock_write().move_as_ok(); return std::make_pair(kv_.set(key, value), std::move(lock)); } + SeqNo erase(const string &key) { auto lock = rw_mutex_.lock_write().move_as_ok(); return kv_.erase(key); } + std::pair<SeqNo, RwMutex::WriteLock> erase_and_lock(const string &key) { auto lock = rw_mutex_.lock_write().move_as_ok(); return std::make_pair(kv_.erase(key), std::move(lock)); } - string get(const string &key) { + + string get(const string &key) const { auto lock = rw_mutex_.lock_read().move_as_ok(); return kv_.get(key); } + + bool isset(const string &key) const { + auto lock = rw_mutex_.lock_read().move_as_ok(); + return kv_.isset(key); + } + size_t size() const { return kv_.size(); } - std::unordered_map<string, string> get_all() { + + std::unordered_map<string, string, Hash<string>> get_all() const { auto lock = rw_mutex_.lock_write().move_as_ok(); return kv_.get_all(); } - // not thread safe method + + // non-thread-safe method SeqKeyValue &inner() { return kv_; } @@ -65,7 +79,8 @@ class TsSeqKeyValue { } private: - RwMutex rw_mutex_; + mutable RwMutex rw_mutex_; SeqKeyValue kv_; }; + } // namespace td |