mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix possible deadlock in debug logs.
This commit is contained in:
parent
2d8f43bd8c
commit
e7ca35a276
3 changed files with 22 additions and 4 deletions
|
@ -420,7 +420,6 @@ void Launcher::prepareSettings() {
|
||||||
|
|
||||||
void Launcher::initQtMessageLogging() {
|
void Launcher::initQtMessageLogging() {
|
||||||
static QtMessageHandler OriginalMessageHandler = nullptr;
|
static QtMessageHandler OriginalMessageHandler = nullptr;
|
||||||
static bool WritingQtMessage = false;
|
|
||||||
OriginalMessageHandler = qInstallMessageHandler([](
|
OriginalMessageHandler = qInstallMessageHandler([](
|
||||||
QtMsgType type,
|
QtMsgType type,
|
||||||
const QMessageLogContext &context,
|
const QMessageLogContext &context,
|
||||||
|
@ -429,10 +428,9 @@ void Launcher::initQtMessageLogging() {
|
||||||
OriginalMessageHandler(type, context, msg);
|
OriginalMessageHandler(type, context, msg);
|
||||||
}
|
}
|
||||||
if (Logs::DebugEnabled() || !Logs::started()) {
|
if (Logs::DebugEnabled() || !Logs::started()) {
|
||||||
if (!WritingQtMessage) {
|
if (!Logs::WritingEntry()) {
|
||||||
WritingQtMessage = true;
|
// Sometimes Qt logs something inside our own logging.
|
||||||
LOG((msg));
|
LOG((msg));
|
||||||
WritingQtMessage = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -14,6 +14,17 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::atomic<int> ThreadCounter/* = 0*/;
|
std::atomic<int> ThreadCounter/* = 0*/;
|
||||||
|
thread_local bool WritingEntryFlag/* = false*/;
|
||||||
|
|
||||||
|
class WritingEntryScope final {
|
||||||
|
public:
|
||||||
|
WritingEntryScope() {
|
||||||
|
WritingEntryFlag = true;
|
||||||
|
}
|
||||||
|
~WritingEntryScope() {
|
||||||
|
WritingEntryFlag = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -73,6 +84,8 @@ public:
|
||||||
|
|
||||||
void closeMain() {
|
void closeMain() {
|
||||||
QMutexLocker lock(_logsMutex(LogDataMain));
|
QMutexLocker lock(_logsMutex(LogDataMain));
|
||||||
|
WritingEntryScope scope;
|
||||||
|
|
||||||
const auto file = files[LogDataMain].get();
|
const auto file = files[LogDataMain].get();
|
||||||
if (file && file->isOpen()) {
|
if (file && file->isOpen()) {
|
||||||
file->close();
|
file->close();
|
||||||
|
@ -98,6 +111,8 @@ public:
|
||||||
|
|
||||||
void write(LogDataType type, const QString &msg) {
|
void write(LogDataType type, const QString &msg) {
|
||||||
QMutexLocker lock(_logsMutex(type));
|
QMutexLocker lock(_logsMutex(type));
|
||||||
|
WritingEntryScope scope;
|
||||||
|
|
||||||
if (type != LogDataMain) {
|
if (type != LogDataMain) {
|
||||||
reopenDebug();
|
reopenDebug();
|
||||||
}
|
}
|
||||||
|
@ -323,6 +338,10 @@ bool DebugEnabled() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WritingEntry() {
|
||||||
|
return WritingEntryFlag;
|
||||||
|
}
|
||||||
|
|
||||||
void start(not_null<Core::Launcher*> launcher) {
|
void start(not_null<Core::Launcher*> launcher) {
|
||||||
Assert(LogsData == nullptr);
|
Assert(LogsData == nullptr);
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ namespace Logs {
|
||||||
|
|
||||||
void SetDebugEnabled(bool enabled);
|
void SetDebugEnabled(bool enabled);
|
||||||
bool DebugEnabled();
|
bool DebugEnabled();
|
||||||
|
[[nodiscard]] bool WritingEntry();
|
||||||
|
|
||||||
void start(not_null<Core::Launcher*> launcher);
|
void start(not_null<Core::Launcher*> launcher);
|
||||||
bool started();
|
bool started();
|
||||||
|
|
Loading…
Add table
Reference in a new issue