Protect access to some static variables using ExitGuard.
GitOrigin-RevId: 65c7510c60d585b90e90d09067c7dfdaf79c4cd3
This commit is contained in:
parent
7207d76a80
commit
09f906f192
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
#include "td/utils/crypto.h"
|
#include "td/utils/crypto.h"
|
||||||
|
#include "td/utils/ExitGuard.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/MpscPollableQueue.h"
|
#include "td/utils/MpscPollableQueue.h"
|
||||||
|
@ -174,7 +175,7 @@ class ClientManager::Impl final {
|
||||||
td.second.reset();
|
td.second.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (!tds_.empty()) {
|
while (!tds_.empty() && !ExitGuard::is_exited()) {
|
||||||
receive(10);
|
receive(10);
|
||||||
}
|
}
|
||||||
concurrent_scheduler_->finish();
|
concurrent_scheduler_->finish();
|
||||||
|
@ -521,7 +522,7 @@ class ClientManager::Impl final {
|
||||||
for (auto &it : impls_) {
|
for (auto &it : impls_) {
|
||||||
close_impl(it.first);
|
close_impl(it.first);
|
||||||
}
|
}
|
||||||
while (!impls_.empty()) {
|
while (!impls_.empty() && !ExitGuard::is_exited()) {
|
||||||
receive(10);
|
receive(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -569,7 +570,7 @@ class Client::Impl final {
|
||||||
Impl &operator=(Impl &&) = delete;
|
Impl &operator=(Impl &&) = delete;
|
||||||
~Impl() {
|
~Impl() {
|
||||||
multi_impl_->close(td_id_);
|
multi_impl_->close(td_id_);
|
||||||
while (true) {
|
while (!ExitGuard::is_exited()) {
|
||||||
auto response = receiver_.receive(10.0);
|
auto response = receiver_.receive(10.0);
|
||||||
if (response.object == nullptr && response.client_id != 0 && response.request_id == 0) {
|
if (response.object == nullptr && response.client_id != 0 && response.request_id == 0) {
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "td/telegram/td_api_json.h"
|
#include "td/telegram/td_api_json.h"
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/ExitGuard.h"
|
||||||
#include "td/utils/JsonBuilder.h"
|
#include "td/utils/JsonBuilder.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/port/thread_local.h"
|
#include "td/utils/port/thread_local.h"
|
||||||
|
@ -116,6 +117,7 @@ const char *ClientJson::execute(Slice request) {
|
||||||
|
|
||||||
static ClientManager *get_manager() {
|
static ClientManager *get_manager() {
|
||||||
static ClientManager client_manager;
|
static ClientManager client_manager;
|
||||||
|
static ExitGuard exit_guard;
|
||||||
return &client_manager;
|
return &client_manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "td/utils/common.h"
|
#include "td/utils/common.h"
|
||||||
|
#include "td/utils/ExitGuard.h"
|
||||||
#include "td/utils/logging.h"
|
#include "td/utils/logging.h"
|
||||||
#include "td/utils/misc.h"
|
#include "td/utils/misc.h"
|
||||||
#include "td/utils/port/detail/PollableFd.h"
|
#include "td/utils/port/detail/PollableFd.h"
|
||||||
|
@ -356,6 +357,7 @@ Result<size_t> FileFd::pread(MutableSlice slice, int64 offset) const {
|
||||||
|
|
||||||
static std::mutex in_process_lock_mutex;
|
static std::mutex in_process_lock_mutex;
|
||||||
static std::unordered_set<string> locked_files;
|
static std::unordered_set<string> locked_files;
|
||||||
|
static ExitGuard exit_guard;
|
||||||
|
|
||||||
static Status create_local_lock(const string &path, int32 &max_tries) {
|
static Status create_local_lock(const string &path, int32 &max_tries) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -469,12 +471,13 @@ Status FileFd::lock(const LockFlags flags, const string &path, int32 max_tries)
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileFd::remove_local_lock(const string &path) {
|
void FileFd::remove_local_lock(const string &path) {
|
||||||
if (!path.empty()) {
|
if (path.empty() || ExitGuard::is_exited()) {
|
||||||
VLOG(fd) << "Unlock file \"" << path << '"';
|
return;
|
||||||
std::unique_lock<std::mutex> lock(in_process_lock_mutex);
|
|
||||||
auto erased_count = locked_files.erase(path);
|
|
||||||
CHECK(erased_count > 0);
|
|
||||||
}
|
}
|
||||||
|
VLOG(fd) << "Unlock file \"" << path << '"';
|
||||||
|
std::unique_lock<std::mutex> lock(in_process_lock_mutex);
|
||||||
|
auto erased_count = locked_files.erase(path);
|
||||||
|
CHECK(erased_count > 0 || ExitGuard::is_exited());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileFd::close() {
|
void FileFd::close() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user