mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Testing crl (concurrency runtime library).
This commit is contained in:
@@ -23,6 +23,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
#include "platform/platform_launcher.h"
|
||||
#include "platform/platform_specific.h"
|
||||
#include "core/crash_reports.h"
|
||||
#include "core/main_queue_processor.h"
|
||||
#include "application.h"
|
||||
|
||||
namespace Core {
|
||||
@@ -63,11 +64,7 @@ int Launcher::exec() {
|
||||
Logs::start(this); // must be started before Platform is started
|
||||
Platform::start(); // must be started before QApplication is created
|
||||
|
||||
auto result = 0;
|
||||
{
|
||||
Application app(this, _argc, _argv);
|
||||
result = app.exec();
|
||||
}
|
||||
auto result = executeApplication();
|
||||
|
||||
DEBUG_LOG(("Telegram finished, result: %1").arg(result));
|
||||
|
||||
@@ -240,4 +237,10 @@ void Launcher::processArguments() {
|
||||
gStartUrl = parseResult.value("--", QStringList()).join(QString());
|
||||
}
|
||||
|
||||
int Launcher::executeApplication() {
|
||||
MainQueueProcessor processor;
|
||||
Application app(this, _argc, _argv);
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
@@ -58,6 +58,7 @@ private:
|
||||
|
||||
virtual bool launchUpdater(UpdaterLaunch action) = 0;
|
||||
|
||||
int executeApplication();
|
||||
|
||||
int _argc;
|
||||
char **_argv;
|
||||
|
96
Telegram/SourceFiles/core/main_queue_processor.cpp
Normal file
96
Telegram/SourceFiles/core/main_queue_processor.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop version of Telegram messaging app, see https://telegram.org
|
||||
|
||||
Telegram Desktop is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
In addition, as a special exception, the copyright holders give permission
|
||||
to link the code of portions of this program with the OpenSSL library.
|
||||
|
||||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
||||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
*/
|
||||
#include "core/main_queue_processor.h"
|
||||
|
||||
namespace Core {
|
||||
namespace {
|
||||
|
||||
QMutex ProcessorMutex;
|
||||
MainQueueProcessor *ProcessorInstance/* = nullptr*/;
|
||||
|
||||
constexpr auto kProcessorEvent = QEvent::Type(QEvent::User + 1);
|
||||
static_assert(kProcessorEvent < QEvent::MaxUser);
|
||||
|
||||
class ProcessorEvent : public QEvent {
|
||||
public:
|
||||
ProcessorEvent(void (*callable)(void*), void *argument);
|
||||
|
||||
void process();
|
||||
|
||||
private:
|
||||
void (*_callable)(void*) = nullptr;
|
||||
void *_argument = nullptr;
|
||||
|
||||
};
|
||||
|
||||
ProcessorEvent::ProcessorEvent(void (*callable)(void*), void *argument)
|
||||
: QEvent(kProcessorEvent)
|
||||
, _callable(callable)
|
||||
, _argument(argument) {
|
||||
}
|
||||
|
||||
void ProcessorEvent::process() {
|
||||
_callable(_argument);
|
||||
}
|
||||
|
||||
void ProcessMainQueue(void (*callable)(void*), void *argument) {
|
||||
QMutexLocker lock(&ProcessorMutex);
|
||||
|
||||
if (ProcessorInstance) {
|
||||
const auto event = new ProcessorEvent(callable, argument);
|
||||
QCoreApplication::postEvent(ProcessorInstance, event);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
MainQueueProcessor::MainQueueProcessor() {
|
||||
acquire();
|
||||
crl::init_main_queue(ProcessMainQueue);
|
||||
}
|
||||
|
||||
bool MainQueueProcessor::event(QEvent *event) {
|
||||
if (event->type() == kProcessorEvent) {
|
||||
static_cast<ProcessorEvent*>(event)->process();
|
||||
return true;
|
||||
}
|
||||
return QObject::event(event);
|
||||
}
|
||||
|
||||
void MainQueueProcessor::acquire() {
|
||||
Expects(ProcessorInstance == nullptr);
|
||||
|
||||
QMutexLocker lock(&ProcessorMutex);
|
||||
ProcessorInstance = this;
|
||||
}
|
||||
|
||||
void MainQueueProcessor::release() {
|
||||
Expects(ProcessorInstance == this);
|
||||
|
||||
QMutexLocker lock(&ProcessorMutex);
|
||||
ProcessorInstance = nullptr;
|
||||
}
|
||||
|
||||
MainQueueProcessor::~MainQueueProcessor() {
|
||||
release();
|
||||
}
|
||||
|
||||
} // namespace
|
40
Telegram/SourceFiles/core/main_queue_processor.h
Normal file
40
Telegram/SourceFiles/core/main_queue_processor.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop version of Telegram messaging app, see https://telegram.org
|
||||
|
||||
Telegram Desktop is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
It is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
In addition, as a special exception, the copyright holders give permission
|
||||
to link the code of portions of this program with the OpenSSL library.
|
||||
|
||||
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
||||
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Core {
|
||||
|
||||
class MainQueueProcessor : public QObject {
|
||||
public:
|
||||
MainQueueProcessor();
|
||||
|
||||
~MainQueueProcessor();
|
||||
|
||||
protected:
|
||||
bool event(QEvent *event) override;
|
||||
|
||||
private:
|
||||
void acquire();
|
||||
void release();
|
||||
|
||||
};
|
||||
|
||||
} // namespace Core
|
Reference in New Issue
Block a user