Testing crl (concurrency runtime library).
This commit is contained in:
parent
499e3113b9
commit
b8204a317d
|
@ -10,3 +10,6 @@
|
|||
[submodule "Telegram/ThirdParty/Catch"]
|
||||
path = Telegram/ThirdParty/Catch
|
||||
url = https://github.com/philsquared/Catch
|
||||
[submodule "Telegram/ThirdParty/crl"]
|
||||
path = Telegram/ThirdParty/crl
|
||||
url = https://github.com/telegramdesktop/crl.git
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
|
@ -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
|
|
@ -1596,9 +1596,9 @@ void MediaView::initThemePreview() {
|
|||
current.backgroundId = Window::Theme::Background()->id();
|
||||
current.backgroundImage = Window::Theme::Background()->pixmap();
|
||||
current.backgroundTiled = Window::Theme::Background()->tile();
|
||||
base::TaskQueue::Normal().Put([ready = std::move(ready), path, current]() mutable {
|
||||
crl::async([=] {
|
||||
auto preview = Window::Theme::GeneratePreview(path, current);
|
||||
base::TaskQueue::Main().Put([ready = std::move(ready), result = std::move(preview)]() mutable {
|
||||
crl::on_main([ready, result = std::move(preview)]() mutable {
|
||||
ready(std::move(result));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -77,6 +77,7 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|||
|
||||
#include <gsl/gsl>
|
||||
#include <rpl/rpl.h>
|
||||
#include <crl/crl.h>
|
||||
|
||||
#include "base/variant.h"
|
||||
#include "base/optional.h"
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 68d321c9a509256be86fa13097ec84a6c51b6a58
|
|
@ -84,6 +84,7 @@
|
|||
'tests/tests.gyp:tests',
|
||||
'utils.gyp:Updater',
|
||||
'../ThirdParty/libtgvoip/libtgvoip.gyp:libtgvoip',
|
||||
'crl.gyp:crl',
|
||||
],
|
||||
|
||||
'defines': [
|
||||
|
@ -108,6 +109,7 @@
|
|||
'<(emoji_suggestions_loc)',
|
||||
'<(submodules_loc)/GSL/include',
|
||||
'<(submodules_loc)/variant/include',
|
||||
'<(submodules_loc)/crl/src',
|
||||
],
|
||||
'sources': [
|
||||
'<@(qrc_files)',
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
# 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 John Preston, https://desktop.telegram.org
|
||||
|
||||
{
|
||||
'includes': [
|
||||
'common.gypi',
|
||||
],
|
||||
'targets': [{
|
||||
'target_name': 'crl',
|
||||
'type': 'static_library',
|
||||
'dependencies': [],
|
||||
'includes': [
|
||||
'common.gypi',
|
||||
'qt.gypi',
|
||||
],
|
||||
'defines': [
|
||||
],
|
||||
'variables': {
|
||||
'crl_src_loc': '../ThirdParty/crl/src/crl',
|
||||
'official_build_target%': '',
|
||||
},
|
||||
'include_dirs': [
|
||||
'../ThirdParty/crl/src',
|
||||
],
|
||||
'sources': [
|
||||
'<(crl_src_loc)/common/crl_common_config.h',
|
||||
'<(crl_src_loc)/common/crl_common_list.cpp',
|
||||
'<(crl_src_loc)/common/crl_common_list.h',
|
||||
'<(crl_src_loc)/common/crl_common_on_main.cpp',
|
||||
'<(crl_src_loc)/common/crl_common_on_main.h',
|
||||
'<(crl_src_loc)/common/crl_common_queue.cpp',
|
||||
'<(crl_src_loc)/common/crl_common_queue.h',
|
||||
'<(crl_src_loc)/common/crl_common_sync.h',
|
||||
'<(crl_src_loc)/common/crl_common_utils.h',
|
||||
'<(crl_src_loc)/dispatch/crl_dispatch_async.cpp',
|
||||
'<(crl_src_loc)/dispatch/crl_dispatch_async.h',
|
||||
'<(crl_src_loc)/dispatch/crl_dispatch_on_main.h',
|
||||
'<(crl_src_loc)/dispatch/crl_dispatch_queue.cpp',
|
||||
'<(crl_src_loc)/dispatch/crl_dispatch_queue.h',
|
||||
'<(crl_src_loc)/dispatch/crl_dispatch_semaphore.cpp',
|
||||
'<(crl_src_loc)/dispatch/crl_dispatch_semaphore.h',
|
||||
'<(crl_src_loc)/qt/crl_qt_async.cpp',
|
||||
'<(crl_src_loc)/qt/crl_qt_async.h',
|
||||
'<(crl_src_loc)/qt/crl_qt_semaphore.cpp',
|
||||
'<(crl_src_loc)/qt/crl_qt_semaphore.h',
|
||||
'<(crl_src_loc)/winapi/crl_winapi_async.cpp',
|
||||
'<(crl_src_loc)/winapi/crl_winapi_async.h',
|
||||
'<(crl_src_loc)/winapi/crl_winapi_dll.h',
|
||||
'<(crl_src_loc)/winapi/crl_winapi_list.cpp',
|
||||
'<(crl_src_loc)/winapi/crl_winapi_list.h',
|
||||
'<(crl_src_loc)/winapi/crl_winapi_semaphore.cpp',
|
||||
'<(crl_src_loc)/winapi/crl_winapi_semaphore.h',
|
||||
'<(crl_src_loc)/crl.h',
|
||||
'<(crl_src_loc)/crl_async.h',
|
||||
'<(crl_src_loc)/crl_on_main.h',
|
||||
'<(crl_src_loc)/crl_queue.h',
|
||||
'<(crl_src_loc)/crl_semaphore.h',
|
||||
],
|
||||
}],
|
||||
}
|
|
@ -149,6 +149,8 @@
|
|||
<(src_loc)/core/file_utilities.h
|
||||
<(src_loc)/core/launcher.cpp
|
||||
<(src_loc)/core/launcher.h
|
||||
<(src_loc)/core/main_queue_processor.cpp
|
||||
<(src_loc)/core/main_queue_processor.h
|
||||
<(src_loc)/core/single_timer.cpp
|
||||
<(src_loc)/core/single_timer.h
|
||||
<(src_loc)/core/tl_help.h
|
||||
|
|
Loading…
Reference in New Issue