Commit 4cf53dae8b1a025536e43bd2db9b877203a9be61
1 parent
141d804a
threading tweaks based on improved understanding
Showing
2 changed files
with
7 additions
and
5 deletions
app/br/br.cpp
| ... | ... | @@ -231,7 +231,6 @@ int main(int argc, char *argv[]) |
| 231 | 231 | br_initialize(argc, argv); |
| 232 | 232 | |
| 233 | 233 | FakeMain *fakeMain = new FakeMain(argc, argv); |
| 234 | - QThreadPool::globalInstance()->releaseThread(); | |
| 235 | 234 | QThreadPool::globalInstance()->start(fakeMain); |
| 236 | 235 | QCoreApplication::exec(); |
| 237 | 236 | ... | ... |
openbr/openbr_plugin.cpp
| ... | ... | @@ -876,6 +876,9 @@ void br::Context::initialize(int &argc, char *argv[], QString sdkPath) |
| 876 | 876 | } |
| 877 | 877 | Globals->sdkPath = sdkPath; |
| 878 | 878 | |
| 879 | + // Empirical evidence suggests an extra thread helps achieve full CPU utilization | |
| 880 | + QThreadPool::globalInstance()->releaseThread(); | |
| 881 | + | |
| 879 | 882 | // Trigger registered initializers |
| 880 | 883 | QList< QSharedPointer<Initializer> > initializers = Factory<Initializer>::makeAll(); |
| 881 | 884 | foreach (const QSharedPointer<Initializer> &initializer, initializers) |
| ... | ... | @@ -884,6 +887,9 @@ void br::Context::initialize(int &argc, char *argv[], QString sdkPath) |
| 884 | 887 | |
| 885 | 888 | void br::Context::finalize() |
| 886 | 889 | { |
| 890 | + // Undo the 'releaseThread()' in 'initialize()' | |
| 891 | + QThreadPool::globalInstance()->reserveThread(); | |
| 892 | + | |
| 887 | 893 | // Trigger registered finalizers |
| 888 | 894 | QList< QSharedPointer<Initializer> > initializers = Factory<Initializer>::makeAll(); |
| 889 | 895 | foreach (const QSharedPointer<Initializer> &initializer, initializers) |
| ... | ... | @@ -1295,10 +1301,7 @@ void Transform::project(const TemplateList &src, TemplateList &dst) const |
| 1295 | 1301 | |
| 1296 | 1302 | // There are certain conditions where we should process the templates in serial, |
| 1297 | 1303 | // but generally we'd prefer to process them in parallel. |
| 1298 | - if ((src.size() < 2) || | |
| 1299 | - (QThreadPool::globalInstance()->activeThreadCount() >= QThreadPool::globalInstance()->maxThreadCount()) || | |
| 1300 | - (Globals->parallelism == 0)) { | |
| 1301 | - | |
| 1304 | + if ((src.size() < 2) || (Globals->parallelism == 0)) { | |
| 1302 | 1305 | foreach (const Template &t, src) { |
| 1303 | 1306 | dst.append(Template()); |
| 1304 | 1307 | _project(this, &t, &dst.last()); | ... | ... |