Actors: safer tag_ in context
GitOrigin-RevId: 9f9ef2a024e0bcfb0e5aed76a23174f1faad3b5a
This commit is contained in:
parent
f0d1afcb7a
commit
ce80dd77f0
@ -6,6 +6,7 @@
|
||||
//
|
||||
#include "td/telegram/Client.h"
|
||||
|
||||
#include "td/actor/impl/ActorInfo-decl.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/TdCallback.h"
|
||||
|
||||
@ -37,18 +38,9 @@ class MultiTd : public Actor {
|
||||
CHECK(td.empty());
|
||||
|
||||
string name = "Td";
|
||||
class TdActorContext : public ActorContext {
|
||||
public:
|
||||
explicit TdActorContext(string tag) : tag_(std::move(tag)) {
|
||||
}
|
||||
int32 get_id() const override {
|
||||
return 0x172ae58d;
|
||||
}
|
||||
string tag_;
|
||||
};
|
||||
auto context = std::make_shared<TdActorContext>(to_string(td_id));
|
||||
auto context = std::make_shared<td::ActorContext>();
|
||||
auto old_context = set_context(context);
|
||||
auto old_tag = set_tag(context->tag_);
|
||||
auto old_tag = set_tag(to_string(td_id));
|
||||
td = create_actor<Td>("Td", std::move(callback), options_);
|
||||
set_context(old_context);
|
||||
set_tag(old_tag);
|
||||
|
@ -75,7 +75,7 @@ class Actor : public ObserverBase {
|
||||
|
||||
uint64 get_link_token();
|
||||
std::shared_ptr<ActorContext> set_context(std::shared_ptr<ActorContext> context);
|
||||
CSlice set_tag(CSlice tag);
|
||||
string set_tag(string tag);
|
||||
|
||||
void always_wait_for_mailbox();
|
||||
|
||||
|
@ -88,13 +88,13 @@ inline uint64 Actor::get_link_token() {
|
||||
inline std::shared_ptr<ActorContext> Actor::set_context(std::shared_ptr<ActorContext> context) {
|
||||
return info_->set_context(std::move(context));
|
||||
}
|
||||
inline CSlice Actor::set_tag(CSlice tag) {
|
||||
auto &tag_ref = info_->get_context()->tag_;
|
||||
CSlice old_tag;
|
||||
if (tag_ref) {
|
||||
old_tag = CSlice(tag_ref);
|
||||
inline string Actor::set_tag(string tag) {
|
||||
auto *ctx = info_->get_context();
|
||||
string old_tag;
|
||||
if (ctx->tag_) {
|
||||
old_tag = ctx->tag_;
|
||||
}
|
||||
tag_ref = tag.c_str();
|
||||
ctx->set_tag(std::move(tag));
|
||||
Scheduler::on_context_updated();
|
||||
return old_tag;
|
||||
}
|
||||
|
@ -37,7 +37,13 @@ class ActorContext {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void set_tag(string tag) {
|
||||
tag_storage_ = std::move(tag);
|
||||
tag_ = tag_storage_.c_str();
|
||||
}
|
||||
|
||||
const char *tag_ = nullptr;
|
||||
string tag_storage_; // sometimes tag_ == tag_storage_.c_str()
|
||||
std::weak_ptr<ActorContext> this_ptr_;
|
||||
};
|
||||
|
||||
|
@ -840,7 +840,7 @@ class Tdclient_login : public Test {
|
||||
|
||||
TEST(Client, Simple) {
|
||||
td::Client client;
|
||||
//client.execute({1, td::td_api::make_object<td::td_api::setLogTagVerbosityLevel>("actor", 1)});
|
||||
client.execute({1, td::td_api::make_object<td::td_api::setLogTagVerbosityLevel>("actor", 1)});
|
||||
client.send({3, td::make_tl_object<td::td_api::testSquareInt>(3)});
|
||||
while (true) {
|
||||
auto result = client.receive(10);
|
||||
|
Loading…
Reference in New Issue
Block a user