Skip to content
Snippets Groups Projects
Commit 3b31bdf6 authored by Morten Sorvig's avatar Morten Sorvig
Browse files

Build in single-threaded mode as well.

parent 16e8b53c
No related branches found
No related tags found
No related merge requests found
...@@ -51,16 +51,21 @@ ...@@ -51,16 +51,21 @@
#include "mandelbrotwidget.h" #include "mandelbrotwidget.h"
#include <QApplication> #include <QApplication>
#if QT_CONFIG(thread)
#include <QThreadPool> #include <QThreadPool>
#endif
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);
// We're managing the number of threads elsewhere; set the global #if QT_CONFIG(thread)
// We're managing the number of threads elsewhere; set the globalw
// thread limit to a large value so it won't interfere. // thread limit to a large value so it won't interfere.
QThreadPool::globalInstance()->setMaxThreadCount(1024); QThreadPool::globalInstance()->setMaxThreadCount(1024);
#endif
MandelbrotWidget widget; MandelbrotWidget widget;
widget.show(); widget.show();
return app.exec(); return app.exec();
......
...@@ -52,13 +52,17 @@ ...@@ -52,13 +52,17 @@
#include <QImage> #include <QImage>
#include <QDebug> #include <QDebug>
#if QT_CONFIG(thread)
#include <QThreadPool> #include <QThreadPool>
#endif
#include <cmath> #include <cmath>
#ifdef Q_OS_WASM #ifdef Q_OS_WASM
#include <emscripten.h> #include <emscripten.h>
#endif #endif
#if QT_CONFIG(thread)
// runs function on a thread from the global QThreadPool, returns a // runs function on a thread from the global QThreadPool, returns a
// function that can be called to vait for the function to finish. // function that can be called to vait for the function to finish.
std::function<void()> runOnThread(std::function<void()> fn) std::function<void()> runOnThread(std::function<void()> fn)
...@@ -103,6 +107,15 @@ std::function<void()> runOnThread(std::function<void()> fn) ...@@ -103,6 +107,15 @@ std::function<void()> runOnThread(std::function<void()> fn)
return waitFn; return waitFn;
} }
#else
std::function<void()> runOnThread(std::function<void()> fn)
{
fn(); // run function right away
return [](){}; // return a no-op wait function
}
#endif // QT_CONFIG(thread)
// calls the provided \a function \a iterationCount times, using at maximum \a maxThreads thrads. // calls the provided \a function \a iterationCount times, using at maximum \a maxThreads thrads.
void runOnThreads(std::function<void(int i)> fn, int iterationCount, void runOnThreads(std::function<void(int i)> fn, int iterationCount,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment