2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Fix possible deadlock in debug logs.

This commit is contained in:
John Preston
2021-05-12 14:48:44 +04:00
parent 2d8f43bd8c
commit e7ca35a276
3 changed files with 22 additions and 4 deletions

View File

@@ -14,6 +14,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace {
std::atomic<int> ThreadCounter/* = 0*/;
thread_local bool WritingEntryFlag/* = false*/;
class WritingEntryScope final {
public:
WritingEntryScope() {
WritingEntryFlag = true;
}
~WritingEntryScope() {
WritingEntryFlag = false;
}
};
} // namespace
@@ -73,6 +84,8 @@ public:
void closeMain() {
QMutexLocker lock(_logsMutex(LogDataMain));
WritingEntryScope scope;
const auto file = files[LogDataMain].get();
if (file && file->isOpen()) {
file->close();
@@ -98,6 +111,8 @@ public:
void write(LogDataType type, const QString &msg) {
QMutexLocker lock(_logsMutex(type));
WritingEntryScope scope;
if (type != LogDataMain) {
reopenDebug();
}
@@ -323,6 +338,10 @@ bool DebugEnabled() {
#endif
}
bool WritingEntry() {
return WritingEntryFlag;
}
void start(not_null<Core::Launcher*> launcher) {
Assert(LogsData == nullptr);