Various improvements.
GitOrigin-RevId: 4eb8b7e43d10f1b5657f40aa2b7eef1c93429ca7
This commit is contained in:
parent
4635b7b791
commit
c055ec15f9
@ -452,7 +452,6 @@ set(TDLIB_SOURCE
|
||||
td/telegram/net/MtprotoHeader.cpp
|
||||
td/telegram/net/NetActor.cpp
|
||||
td/telegram/net/NetQuery.cpp
|
||||
td/telegram/net/NetQueryCounter.cpp
|
||||
td/telegram/net/NetQueryCreator.cpp
|
||||
td/telegram/net/NetQueryDelayer.cpp
|
||||
td/telegram/net/NetQueryDispatcher.cpp
|
||||
|
@ -288,7 +288,7 @@ class TdReceiver {
|
||||
|
||||
class MultiImpl {
|
||||
public:
|
||||
MultiImpl(std::shared_ptr<NetQueryStats> net_query_stats) {
|
||||
explicit MultiImpl(std::shared_ptr<NetQueryStats> net_query_stats) {
|
||||
concurrent_scheduler_ = std::make_shared<ConcurrentScheduler>();
|
||||
concurrent_scheduler_->init(3);
|
||||
concurrent_scheduler_->start();
|
||||
@ -369,10 +369,6 @@ class MultiImplPool {
|
||||
return res;
|
||||
}
|
||||
|
||||
std::shared_ptr<NetQueryStats> get_net_query_stats() const {
|
||||
return net_query_stats_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::mutex mutex_;
|
||||
std::vector<std::weak_ptr<MultiImpl>> impls_;
|
||||
|
@ -8,19 +8,19 @@
|
||||
|
||||
///\file
|
||||
|
||||
#include "td/actor/actor.h"
|
||||
#include "td/telegram/TdCallback.h"
|
||||
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/td_api.hpp"
|
||||
|
||||
#include "td/telegram/TdCallback.h"
|
||||
#include "td/actor/actor.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class Td;
|
||||
class NetQueryStats;
|
||||
class Td;
|
||||
|
||||
/**
|
||||
* This is a low-level Actor interface for interaction with TDLib. The interface is a lot more flexible than
|
||||
@ -30,6 +30,9 @@ class ClientActor : public Actor {
|
||||
public:
|
||||
struct Options {
|
||||
std::shared_ptr<NetQueryStats> net_query_stats;
|
||||
|
||||
Options() {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -423,7 +423,7 @@ class Global : public ActorContext {
|
||||
|
||||
ActorId<StateManager> state_manager_;
|
||||
|
||||
LazySchedulerLocalStorage<td::unique_ptr<NetQueryCreator>> net_query_creator_;
|
||||
LazySchedulerLocalStorage<unique_ptr<NetQueryCreator>> net_query_creator_;
|
||||
unique_ptr<NetQueryDispatcher> net_query_dispatcher_;
|
||||
|
||||
unique_ptr<ConfigShared> shared_config_;
|
||||
|
@ -9,12 +9,12 @@
|
||||
#include "td/telegram/files/FileId.h"
|
||||
#include "td/telegram/net/MtprotoHeader.h"
|
||||
#include "td/telegram/net/NetQuery.h"
|
||||
#include "td/telegram/net/NetQueryStats.h"
|
||||
#include "td/telegram/StateManager.h"
|
||||
#include "td/telegram/TdCallback.h"
|
||||
#include "td/telegram/TdParameters.h"
|
||||
#include "td/telegram/TermsOfService.h"
|
||||
|
||||
#include "td/telegram/net/NetQueryStats.h"
|
||||
#include "td/telegram/td_api.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
|
@ -1,13 +0,0 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2020
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
#include "td/telegram/net/NetQueryCounter.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
std::atomic<uint64> NetQueryCounter::counter_{0};
|
||||
|
||||
} // namespace td
|
@ -9,38 +9,31 @@
|
||||
#include "td/utils/common.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
namespace td {
|
||||
|
||||
class NetQueryCounter {
|
||||
public:
|
||||
using Counter = std::atomic<uint64>;
|
||||
// deprecated
|
||||
NetQueryCounter(bool is_alive = false) {
|
||||
if (is_alive) {
|
||||
*this = NetQueryCounter(&counter_);
|
||||
}
|
||||
}
|
||||
|
||||
static uint64 get_count() {
|
||||
return counter_.load();
|
||||
}
|
||||
NetQueryCounter() = default;
|
||||
|
||||
NetQueryCounter(Counter *counter) : ptr_(counter) {
|
||||
counter->fetch_add(1);
|
||||
explicit NetQueryCounter(Counter *counter) : ptr_(counter) {
|
||||
CHECK(counter != nullptr);
|
||||
counter->fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
explicit operator bool() const {
|
||||
return (bool)ptr_;
|
||||
return static_cast<bool>(ptr_);
|
||||
}
|
||||
|
||||
private:
|
||||
struct Deleter {
|
||||
void operator()(Counter *ptr) {
|
||||
ptr->fetch_sub(1);
|
||||
ptr->fetch_sub(1, std::memory_order_relaxed);
|
||||
}
|
||||
};
|
||||
static Counter counter_;
|
||||
std::unique_ptr<Counter, Deleter> ptr_;
|
||||
};
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "td/telegram/net/DcId.h"
|
||||
#include "td/telegram/net/NetQuery.h"
|
||||
#include "td/telegram/net/NetQueryStats.h"
|
||||
#include "td/telegram/UniqueId.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
|
@ -8,12 +8,13 @@
|
||||
|
||||
#include "td/telegram/net/NetQuery.h"
|
||||
|
||||
#include "td/utils/logging.h"
|
||||
#include "td/utils/format.h"
|
||||
#include "td/utils/logging.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
uint64 NetQueryStats::get_count() const {
|
||||
return count_;
|
||||
return count_.load(std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
void NetQueryStats::dump_pending_network_queries() {
|
||||
|
@ -5,14 +5,16 @@
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/net/NetQueryCounter.h"
|
||||
|
||||
#include "td/utils/int_types.h"
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/TsList.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace td {
|
||||
|
||||
struct NetQueryDebug {
|
||||
double start_timestamp_ = 0;
|
||||
int32 my_id_ = 0;
|
||||
@ -27,11 +29,6 @@ struct NetQueryDebug {
|
||||
|
||||
class NetQueryStats {
|
||||
public:
|
||||
[[deprecated]] static NetQueryStats &get_default_stats() {
|
||||
static NetQueryStats res;
|
||||
return res;
|
||||
}
|
||||
|
||||
NetQueryCounter register_query(TsListNode<NetQueryDebug> *query) {
|
||||
if (use_list_.load(std::memory_order_relaxed)) {
|
||||
list_.put(query);
|
||||
@ -40,6 +37,7 @@ class NetQueryStats {
|
||||
}
|
||||
|
||||
uint64 get_count() const;
|
||||
|
||||
void dump_pending_network_queries();
|
||||
|
||||
private:
|
||||
@ -47,4 +45,5 @@ class NetQueryStats {
|
||||
std::atomic<bool> use_list_{true};
|
||||
TsList<NetQueryDebug> list_;
|
||||
};
|
||||
|
||||
} // namespace td
|
||||
|
Loading…
Reference in New Issue
Block a user