Add more WaitFree* classes usages.
This commit is contained in:
parent
110ef61861
commit
779090f4dd
@ -26,6 +26,7 @@
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/Variant.h"
|
||||
#include "td/utils/WaitFreeVector.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
@ -161,7 +162,7 @@ class FileReferenceManager final : public Actor {
|
||||
FileSourceWallpapers, FileSourceWebPage, FileSourceSavedAnimations,
|
||||
FileSourceRecentStickers, FileSourceFavoriteStickers, FileSourceBackground,
|
||||
FileSourceChatFull, FileSourceChannelFull, FileSourceAppConfig, FileSourceSavedRingtones>;
|
||||
vector<FileSource> file_sources_;
|
||||
WaitFreeVector<FileSource> file_sources_;
|
||||
|
||||
int64 query_generation_{0};
|
||||
|
||||
|
@ -1692,13 +1692,12 @@ StickerType StickersManager::get_sticker_type(FileId file_id) const {
|
||||
}
|
||||
|
||||
bool StickersManager::is_premium_custom_emoji(int64 custom_emoji_id, bool default_result) const {
|
||||
auto it = custom_emoji_to_sticker_id_.find(custom_emoji_id);
|
||||
if (it == custom_emoji_to_sticker_id_.end()) {
|
||||
return default_result;
|
||||
}
|
||||
const Sticker *s = get_sticker(it->second);
|
||||
auto sticker_id = custom_emoji_to_sticker_id_.get(custom_emoji_id);
|
||||
const Sticker *s = get_sticker(sticker_id);
|
||||
if (s == nullptr) {
|
||||
LOG(ERROR) << "Failed to find custom emoji sticker " << it->second;
|
||||
if (sticker_id.is_valid()) {
|
||||
LOG(ERROR) << "Failed to find custom emoji sticker " << sticker_id;
|
||||
}
|
||||
return default_result;
|
||||
}
|
||||
return s->is_premium;
|
||||
@ -2448,11 +2447,8 @@ FileId StickersManager::on_get_sticker(unique_ptr<Sticker> new_sticker, bool rep
|
||||
|
||||
if (s->type == StickerType::CustomEmoji) {
|
||||
auto custom_emoji_id = get_custom_emoji_id(file_id);
|
||||
if (custom_emoji_id != 0) {
|
||||
auto it = custom_emoji_to_sticker_id_.find(custom_emoji_id);
|
||||
if (it != custom_emoji_to_sticker_id_.end() && it->second == file_id) {
|
||||
custom_emoji_to_sticker_id_.erase(it);
|
||||
}
|
||||
if (custom_emoji_id != 0 && custom_emoji_to_sticker_id_.get(custom_emoji_id) == file_id) {
|
||||
custom_emoji_to_sticker_id_.erase(custom_emoji_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -5165,13 +5161,10 @@ td_api::object_ptr<td_api::stickers> StickersManager::get_custom_emoji_stickers_
|
||||
auto update_before_date = G()->unix_time() - 86400;
|
||||
vector<int64> reload_document_ids;
|
||||
for (auto document_id : document_ids) {
|
||||
auto it = custom_emoji_to_sticker_id_.find(document_id);
|
||||
if (it == custom_emoji_to_sticker_id_.end()) {
|
||||
continue;
|
||||
}
|
||||
auto sticker = get_sticker_object(it->second);
|
||||
auto file_id = custom_emoji_to_sticker_id_.get(document_id);
|
||||
auto sticker = get_sticker_object(file_id);
|
||||
if (sticker != nullptr && sticker->type_->get_id() == td_api::stickerTypeCustomEmoji::ID) {
|
||||
auto s = get_sticker(it->second);
|
||||
auto s = get_sticker(file_id);
|
||||
if (s->emoji_receive_date < update_before_date && !s->is_being_reloaded) {
|
||||
s->is_being_reloaded = true;
|
||||
reload_document_ids.push_back(document_id);
|
||||
@ -5206,7 +5199,7 @@ void StickersManager::get_custom_emoji_stickers(vector<int64> &&document_ids, bo
|
||||
|
||||
vector<int64> unknown_document_ids;
|
||||
for (auto document_id : document_ids) {
|
||||
if (custom_emoji_to_sticker_id_.count(document_id) == 0) {
|
||||
if (custom_emoji_to_sticker_id_.get(document_id).is_valid()) {
|
||||
unknown_document_ids.push_back(document_id);
|
||||
}
|
||||
}
|
||||
|
@ -994,7 +994,7 @@ class StickersManager final : public Actor {
|
||||
string emoji_sounds_str_;
|
||||
FlatHashMap<string, FileId> emoji_sounds_;
|
||||
|
||||
FlatHashMap<int64, FileId> custom_emoji_to_sticker_id_;
|
||||
WaitFreeHashMap<int64, FileId> custom_emoji_to_sticker_id_;
|
||||
|
||||
double animated_emoji_zoom_ = 0.0;
|
||||
|
||||
|
@ -952,8 +952,8 @@ void WebPagesManager::on_load_web_page_instant_view_from_database(WebPageId web_
|
||||
// G()->td_db()->get_sqlite_pmc()->erase(get_web_page_instant_view_database_key(web_page_id), Auto());
|
||||
// value.clear();
|
||||
|
||||
auto web_page_it = web_pages_.find(web_page_id);
|
||||
if (web_page_it == web_pages_.end() || web_page_it->second->instant_view.is_empty) {
|
||||
WebPage *web_page = web_pages_.get_pointer(web_page_id);
|
||||
if (web_page == nullptr || web_page->instant_view.is_empty) {
|
||||
// possible if web page loses preview/instant view
|
||||
LOG(WARNING) << "There is no instant view in " << web_page_id;
|
||||
if (!value.empty()) {
|
||||
@ -962,7 +962,6 @@ void WebPagesManager::on_load_web_page_instant_view_from_database(WebPageId web_
|
||||
update_web_page_instant_view_load_requests(web_page_id, true, web_page_id);
|
||||
return;
|
||||
}
|
||||
WebPage *web_page = web_page_it->second.get();
|
||||
auto &web_page_instant_view = web_page->instant_view;
|
||||
if (web_page_instant_view.was_loaded_from_database) {
|
||||
return;
|
||||
@ -1361,12 +1360,7 @@ void WebPagesManager::on_web_page_changed(WebPageId web_page_id, bool have_web_p
|
||||
}
|
||||
|
||||
const WebPagesManager::WebPage *WebPagesManager::get_web_page(WebPageId web_page_id) const {
|
||||
auto p = web_pages_.find(web_page_id);
|
||||
if (p == web_pages_.end()) {
|
||||
return nullptr;
|
||||
} else {
|
||||
return p->second.get();
|
||||
}
|
||||
return web_pages_.get_pointer(web_page_id);
|
||||
}
|
||||
|
||||
const WebPagesManager::WebPageInstantView *WebPagesManager::get_web_page_instant_view(WebPageId web_page_id) const {
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "td/utils/FlatHashSet.h"
|
||||
#include "td/utils/Promise.h"
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/WaitFreeHashMap.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
@ -179,7 +180,7 @@ class WebPagesManager final : public Actor {
|
||||
|
||||
Td *td_;
|
||||
ActorShared<> parent_;
|
||||
FlatHashMap<WebPageId, unique_ptr<WebPage>, WebPageIdHash> web_pages_;
|
||||
WaitFreeHashMap<WebPageId, unique_ptr<WebPage>, WebPageIdHash> web_pages_;
|
||||
|
||||
FlatHashMap<WebPageId, vector<Promise<Unit>>, WebPageIdHash> load_web_page_from_database_queries_;
|
||||
FlatHashSet<WebPageId, WebPageIdHash> loaded_from_database_web_pages_;
|
||||
|
@ -3174,11 +3174,11 @@ Result<FileId> FileManager::get_input_file_id(FileType type, const tl_object_ptr
|
||||
auto r_file_content = read_file_str(path, r_stat.ok().size_);
|
||||
if (r_file_content.is_ok()) {
|
||||
hash = sha256(r_file_content.ok());
|
||||
auto it = file_hash_to_file_id_.find(hash);
|
||||
if (it != file_hash_to_file_id_.end()) {
|
||||
auto file_view = get_file_view(it->second);
|
||||
auto file_id = file_hash_to_file_id_.get(hash);
|
||||
if (file_id.is_valid()) {
|
||||
auto file_view = get_file_view(file_id);
|
||||
if (!file_view.empty() && file_view.has_remote_location() && !file_view.remote_location().is_web()) {
|
||||
return it->second;
|
||||
return file_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3186,7 +3186,7 @@ Result<FileId> FileManager::get_input_file_id(FileType type, const tl_object_ptr
|
||||
}
|
||||
TRY_RESULT(file_id, register_local(FullLocalFileLocation(new_type, path, 0), owner_dialog_id, 0, get_by_hash));
|
||||
if (!hash.empty()) {
|
||||
file_hash_to_file_id_[hash] = file_id;
|
||||
file_hash_to_file_id_.set(hash, file_id);
|
||||
}
|
||||
return file_id;
|
||||
}
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "td/utils/Slice.h"
|
||||
#include "td/utils/Status.h"
|
||||
#include "td/utils/StringBuilder.h"
|
||||
#include "td/utils/WaitFreeHashMap.h"
|
||||
#include "td/utils/WaitFreeVector.h"
|
||||
|
||||
#include <map>
|
||||
@ -583,7 +584,7 @@ class FileManager final : public FileLoadManager::Callback {
|
||||
};
|
||||
Enumerator<RemoteInfo> remote_location_info_;
|
||||
|
||||
FlatHashMap<string, FileId> file_hash_to_file_id_;
|
||||
WaitFreeHashMap<string, FileId> file_hash_to_file_id_;
|
||||
|
||||
std::map<FullLocalFileLocation, FileId> local_location_to_file_id_;
|
||||
std::map<FullGenerateFileLocation, FileId> generate_location_to_file_id_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user