2
* Copyright (C) 2016 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authors: James Henstridge <james.henstridge@canonical.com>
21
#include <boost/version.hpp>
23
#if BOOST_VERSION >= 105600
24
# define SF_SUPPORTS_EXECUTORS
26
#ifdef SF_SUPPORTS_EXECUTORS
27
# include <boost/thread/executor.hpp>
42
#ifdef SF_SUPPORTS_EXECUTORS
44
/* Declare future continuations like so to execute within the event
47
* auto f2 = f.then(EXEC_IN_MAIN [](decltype(f) f) { ... });
49
* On Boost >= 1.56, this will use a custom executor to run the
50
* continuation as an event in the main thread. On older versions,
51
* the continuation will be executed in a new thread.
54
#define EXEC_IN_MAIN MainLoopExecutor::instance(),
56
class MainLoopExecutor : public QObject, public boost::executors::executor {
59
static MainLoopExecutor& instance();
61
void submit(work&& closure) override;
62
void close() override;
63
bool closed() override;
64
bool try_executing_one() override;
66
bool event(QEvent *event) override;
70
void execute(work& closure) noexcept;
72
Q_DISABLE_COPY(MainLoopExecutor)
77
#define EXEC_IN_MAIN /*nothing*/