Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-webassembly-examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Morten Sorvig
qt-webassembly-examples
Commits
3b31bdf6
Commit
3b31bdf6
authored
2 years ago
by
Morten Sorvig
Browse files
Options
Downloads
Patches
Plain Diff
Build in single-threaded mode as well.
parent
16e8b53c
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
mandelbrot/main.cpp
+8
-3
8 additions, 3 deletions
mandelbrot/main.cpp
mandelbrot/renderthread.cpp
+13
-0
13 additions, 0 deletions
mandelbrot/renderthread.cpp
with
21 additions
and
3 deletions
mandelbrot/main.cpp
+
8
−
3
View file @
3b31bdf6
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
mandelbrot/renderthread.cpp
+
13
−
0
View file @
3b31bdf6
...
@@ -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
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment