parallelize using libdispatch (Grand Central Dispatch)
This commit is contained in:
parent
dec128d769
commit
a121fb7d8f
|
@ -24,4 +24,5 @@ add_executable(dylibbundler
|
|||
src/Settings.h
|
||||
src/Utils.cpp
|
||||
src/Utils.h
|
||||
src/ParallelForEach.h
|
||||
)
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
//#include "DylibBundler.h"
|
||||
|
||||
class DylibBundler;
|
||||
|
||||
class Dependency {
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <linux/limits.h>
|
||||
#endif
|
||||
|
||||
#include "ParallelForEach.h"
|
||||
#include "Dependency.h"
|
||||
#include "Utils.h"
|
||||
|
||||
|
@ -161,18 +162,18 @@ void DylibBundler::bundleDependencies()
|
|||
// copy & fix up dependencies
|
||||
if (bundleLibs()) {
|
||||
createDestDir();
|
||||
for (const auto& dep : deps) {
|
||||
parallel_for_each(deps.begin(), deps.end(), [&](Dependency* dep) {
|
||||
dep->CopyToBundle();
|
||||
changeLibPathsOnFile(dep->InstallPath());
|
||||
fixRpathsOnFile(dep->OriginalPath(), dep->InstallPath());
|
||||
}
|
||||
});
|
||||
}
|
||||
// fix up input files
|
||||
const auto files = filesToFix();
|
||||
for (const auto& file : files) {
|
||||
parallel_for_each(files.begin(), files.end(), [&](const std::string& file) {
|
||||
changeLibPathsOnFile(file);
|
||||
fixRpathsOnFile(file, file);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void DylibBundler::bundleQtPlugins()
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef DYLIBBUNDLER_PARALLELFOREACH_H
|
||||
#define DYLIBBUNDLER_PARALLELFOREACH_H
|
||||
|
||||
#include <iterator>
|
||||
#include <dispatch/dispatch.h>
|
||||
|
||||
template<typename It, typename F>
|
||||
inline void parallel_for_each(It a, It b, F&& f)
|
||||
{
|
||||
size_t count = std::distance(a,b);
|
||||
using data_t = std::pair<It, F>;
|
||||
data_t helper = data_t(a, std::forward<F>(f));
|
||||
dispatch_apply_f(count,
|
||||
dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0),
|
||||
&helper,
|
||||
[](void* ctx, size_t cnt) {
|
||||
auto* d = static_cast<data_t*>(ctx);
|
||||
auto elem_it = std::next(d->first, cnt);
|
||||
(*d).second(*(elem_it));
|
||||
});
|
||||
}
|
||||
|
||||
#endif //DYLIBBUNDLER_PARALLELFOREACH_H
|
Loading…
Reference in New Issue