Store polls in a WaitFreeHashMap.
This commit is contained in:
parent
dd01e73c8f
commit
5491cc3940
|
@ -301,32 +301,23 @@ bool PollManager::is_local_poll_id(PollId poll_id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const PollManager::Poll *PollManager::get_poll(PollId poll_id) const {
|
const PollManager::Poll *PollManager::get_poll(PollId poll_id) const {
|
||||||
auto p = polls_.find(poll_id);
|
return polls_.get_pointer(poll_id);
|
||||||
if (p == polls_.end()) {
|
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
return p->second.get();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const PollManager::Poll *PollManager::get_poll(PollId poll_id) {
|
const PollManager::Poll *PollManager::get_poll(PollId poll_id) {
|
||||||
auto p = polls_.find(poll_id);
|
auto p = polls_.get_pointer(poll_id);
|
||||||
if (p == polls_.end()) {
|
if (p != nullptr) {
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
schedule_poll_unload(poll_id);
|
schedule_poll_unload(poll_id);
|
||||||
return p->second.get();
|
|
||||||
}
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
PollManager::Poll *PollManager::get_poll_editable(PollId poll_id) {
|
PollManager::Poll *PollManager::get_poll_editable(PollId poll_id) {
|
||||||
auto p = polls_.find(poll_id);
|
auto p = polls_.get_pointer(poll_id);
|
||||||
if (p == polls_.end()) {
|
if (p != nullptr) {
|
||||||
return nullptr;
|
|
||||||
} else {
|
|
||||||
schedule_poll_unload(poll_id);
|
schedule_poll_unload(poll_id);
|
||||||
return p->second.get();
|
|
||||||
}
|
}
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PollManager::have_poll(PollId poll_id) const {
|
bool PollManager::have_poll(PollId poll_id) const {
|
||||||
|
@ -649,8 +640,7 @@ PollId PollManager::create_poll(string &&question, vector<string> &&options, boo
|
||||||
|
|
||||||
PollId poll_id(--current_local_poll_id_);
|
PollId poll_id(--current_local_poll_id_);
|
||||||
CHECK(is_local_poll_id(poll_id));
|
CHECK(is_local_poll_id(poll_id));
|
||||||
bool is_inserted = polls_.emplace(poll_id, std::move(poll)).second;
|
polls_.set(poll_id, std::move(poll));
|
||||||
CHECK(is_inserted);
|
|
||||||
return poll_id;
|
return poll_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1523,8 +1513,7 @@ PollId PollManager::on_get_poll(PollId poll_id, tl_object_ptr<telegram_api::poll
|
||||||
|
|
||||||
auto p = make_unique<Poll>();
|
auto p = make_unique<Poll>();
|
||||||
poll = p.get();
|
poll = p.get();
|
||||||
bool is_inserted = polls_.emplace(poll_id, std::move(p)).second;
|
polls_.set(poll_id, std::move(p));
|
||||||
CHECK(is_inserted);
|
|
||||||
}
|
}
|
||||||
CHECK(poll != nullptr);
|
CHECK(poll != nullptr);
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "td/utils/FlatHashSet.h"
|
#include "td/utils/FlatHashSet.h"
|
||||||
#include "td/utils/Promise.h"
|
#include "td/utils/Promise.h"
|
||||||
#include "td/utils/Status.h"
|
#include "td/utils/Status.h"
|
||||||
|
#include "td/utils/WaitFreeHashMap.h"
|
||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
@ -224,7 +225,7 @@ class PollManager final : public Actor {
|
||||||
|
|
||||||
Td *td_;
|
Td *td_;
|
||||||
ActorShared<> parent_;
|
ActorShared<> parent_;
|
||||||
FlatHashMap<PollId, unique_ptr<Poll>, PollIdHash> polls_;
|
WaitFreeHashMap<PollId, unique_ptr<Poll>, PollIdHash> polls_;
|
||||||
|
|
||||||
FlatHashMap<PollId, FlatHashSet<FullMessageId, FullMessageIdHash>, PollIdHash> server_poll_messages_;
|
FlatHashMap<PollId, FlatHashSet<FullMessageId, FullMessageIdHash>, PollIdHash> server_poll_messages_;
|
||||||
FlatHashMap<PollId, FlatHashSet<FullMessageId, FullMessageIdHash>, PollIdHash> other_poll_messages_;
|
FlatHashMap<PollId, FlatHashSet<FullMessageId, FullMessageIdHash>, PollIdHash> other_poll_messages_;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user