Use static mutext in TsList.

GitOrigin-RevId: 00bd863b3d5499d463e838771fe5e4bc9b16a31e
This commit is contained in:
levlam 2020-07-21 02:05:15 +03:00
parent e7ebc22929
commit 23534d218f
2 changed files with 15 additions and 6 deletions

View File

@ -3735,6 +3735,10 @@ void Td::start_up() {
LOG_IF(FATAL, symbol != c) << "TDLib requires little-endian platform";
}
{
TsList<NetQueryDebug>::lock(); // initialize mutex before any NetQuery
}
VLOG(td_init) << "Create Global";
set_context(std::make_shared<Global>());
inc_request_actor_refcnt(); // guard

View File

@ -166,11 +166,19 @@ class TsList : public TsListNode<DataT> {
TsList(TsList &&) = delete;
TsList &operator=(TsList &&) = delete;
~TsList() {
CHECK(ListNode::empty());
auto guard = lock();
while (true) {
auto res = static_cast<TsListNode<DataT> *>(ListNode::get());
if (!res) {
break;
}
res->parent = nullptr;
}
this->parent = nullptr;
}
std::unique_lock<std::mutex> lock() TD_WARN_UNUSED_RESULT {
return std::unique_lock<std::mutex>(mutex_);
static std::unique_lock<std::mutex> lock() TD_WARN_UNUSED_RESULT {
static std::mutex mutex;
return std::unique_lock<std::mutex>(mutex);
}
TsListNode<DataT> *begin() {
return this->get_next();
@ -186,9 +194,6 @@ class TsList : public TsListNode<DataT> {
}
return res;
}
private:
std::mutex mutex_;
};
template <class DataT>