Commit 5ab2b5bc536c20956e74a295d5f8e5fb3947f2d9

Authored by Josh Klontz
1 parent eed899b5

multi-thread br-enroll

app/br-enroll/br-enroll.cpp
... ... @@ -89,7 +89,7 @@ int main(int argc, char *argv[])
89 89 Globals->quiet = true;
90 90 Globals->enrollAll = true;
91 91 algorithm = Transform::fromAlgorithm("FaceRecognition");
92   - br_iterate_utemplates_file(stdin, enroll_utemplate, NULL);
  92 + br_iterate_utemplates_file(stdin, enroll_utemplate, NULL, true);
93 93 Context::finalize();
94 94 return EXIT_SUCCESS;
95 95 }
... ...
app/br-print/br-print.cpp
... ... @@ -45,6 +45,6 @@ int main(int argc, char *argv[])
45 45 for (int i=1; i<argc; i++)
46 46 if (!strcmp(argv[i], "-help")) { help(); exit(EXIT_SUCCESS); }
47 47  
48   - br_iterate_utemplates_file(stdin, print_utemplate, NULL);
  48 + br_iterate_utemplates_file(stdin, print_utemplate, NULL, false);
49 49 return EXIT_SUCCESS;
50 50 }
... ...
app/br-search/br-search.cpp
... ... @@ -198,7 +198,7 @@ int main(int argc, char *argv[])
198 198 galleries.append(MappedGallery(url));
199 199  
200 200 Globals->quiet = true;
201   - br_iterate_utemplates_file(stdin, search_utemplate, NULL);
  201 + br_iterate_utemplates_file(stdin, search_utemplate, NULL, false);
202 202  
203 203 Context::finalize();
204 204 return EXIT_SUCCESS;
... ...
app/br-select/br-select.cpp
... ... @@ -49,6 +49,6 @@ int main(int argc, char *argv[])
49 49 else if (!strcmp(argv[i], "-algorithmID")) algorithmID = new int(atoi(argv[++i]));
50 50 }
51 51  
52   - br_iterate_utemplates_file(stdin, select_utemplate, NULL);
  52 + br_iterate_utemplates_file(stdin, select_utemplate, NULL, false);
53 53 return EXIT_SUCCESS;
54 54 }
... ...
openbr/universal_template.cpp
1 1 #include <QFile>
  2 +#include <QFutureSynchronizer>
2 3 #include <QMutex>
3 4 #include <QMutexLocker>
  5 +#include <QtConcurrent>
4 6 #include <cstdlib>
5 7 #include <cstring>
6 8  
... ... @@ -47,8 +49,15 @@ void br_iterate_utemplates(br_const_utemplate begin, br_const_utemplate end, br_
47 49 }
48 50 }
49 51  
50   -void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context)
  52 +static void callAndFree(br_utemplate_callback callback, br_utemplate t, br_callback_context context)
51 53 {
  54 + callback(t, context);
  55 + free(t);
  56 +}
  57 +
  58 +void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel)
  59 +{
  60 + QFutureSynchronizer<void> futures;
52 61 while (!feof(file)) {
53 62 br_utemplate t = (br_utemplate) malloc(sizeof(br_universal_template));
54 63  
... ... @@ -56,9 +65,11 @@ void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_c
56 65 t = (br_utemplate) realloc(t, sizeof(br_universal_template) + t->size);
57 66 if (fread(t+1, 1, t->size, file) != t->size)
58 67 qFatal("Unexepected EOF when reading universal template data.");
59   - callback(t, context);
  68 + if (parallel) futures.addFuture(QtConcurrent::run(callAndFree, callback, t, context));
  69 + else callAndFree(callback, t, context);
  70 + } else {
  71 + free(t);
60 72 }
61   -
62   - free(t);
63 73 }
  74 + futures.waitForFinished();
64 75 }
... ...
openbr/universal_template.h
... ... @@ -81,7 +81,7 @@ BR_EXPORT void br_iterate_utemplates(br_const_utemplate begin, br_const_utemplat
81 81 * \brief Iterate over br_universal_template in a file.
82 82 * \see br_iterate_utemplates
83 83 */
84   -BR_EXPORT void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context);
  84 +BR_EXPORT void br_iterate_utemplates_file(FILE *file, br_utemplate_callback callback, br_callback_context context, bool parallel);
85 85  
86 86 #ifdef __cplusplus
87 87 }
... ...