refine threading

This commit is contained in:
SCG82 2019-12-12 04:13:49 -08:00
parent ebbd955abd
commit 6625f27f0e
3 changed files with 43 additions and 54 deletions

View File

@ -107,23 +107,19 @@ Dependency::Dependency(std::string path)
char original_file_buffer[PATH_MAX];
std::string original_file;
if (isRpath(path))
{
if (isRpath(path)) {
original_file = searchFilenameInRpaths(path);
}
else if (not realpath(rtrim(path).c_str(), original_file_buffer))
{
else if (not realpath(rtrim(path).c_str(), original_file_buffer)) {
std::cerr << "\n/!\\ WARNING : Cannot resolve path '" << path.c_str() << "'" << std::endl;
original_file = path;
}
else
{
else {
original_file = original_file_buffer;
}
// check if given path is a symlink
if (original_file != rtrim(path))
{
if (original_file != rtrim(path)) {
filename = stripPrefix(original_file);
prefix = original_file.substr(0, original_file.rfind("/")+1);
addSymlink(path);
@ -235,18 +231,16 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
// for symlinks
const int symamount = symlinks.size();
parallel_for(symamount, [&](int start, int end)
for(int n=0; n<symamount; n++)
{
for (int i=0; i<end; ++i)
command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
if(systemp(command) != 0)
{
command = std::string("install_name_tool -change ") + symlinks[i] + " " + getInnerPath() + " " + file_to_fix;
if (systemp(command) != 0)
{
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
}
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
}
});
}
// FIXME - hackish
if (missing_prefixes)
@ -261,17 +255,14 @@ void Dependency::fixFileThatDependsOnMe(std::string file_to_fix)
// for symlinks
const int symamount = symlinks.size();
parallel_for(symamount, [&](int start, int end)
for(int n=0; n<symamount; n++)
{
for (int i=0; i<end; ++i)
command = std::string("install_name_tool -change ") + symlinks[n] + " " + getInnerPath() + " " + file_to_fix;
if (systemp(command) != 0)
{
command = std::string("install_name_tool -change ") + symlinks[i] + " " + getInnerPath() + " " + file_to_fix;
if (systemp(command) != 0)
{
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
}
std::cerr << "\n\nError : An error occured while trying to fix dependencies of " << file_to_fix << std::endl;
exit(1);
}
});
}
}//next
}// end if(missing_prefixes)
}

View File

@ -46,6 +46,7 @@ void changeLibPathsOnFile(std::string file_to_fix)
std::cout << "\n* Fixing dependencies on " << file_to_fix.c_str() << std::endl;
const int dep_amount = deps.size();
std::cout << "changeLibPaths: # of deps: " << dep_amount << std::endl;
parallel_for(dep_amount, [&](int start, int end)
{
for(int i=start; i<end; ++i)
@ -154,7 +155,7 @@ void fixRpathsOnFile(const std::string& original_file, const std::string& file_t
int start = 0;
int end = rpaths_to_fix.size();
std::cout << "# of rpaths to fix: " << rpaths_to_fix.size() << std::endl;
// parallel_for(rpaths_to_fix.size(), [&](int start, int end)
// {
for(int i=start; i<end; ++i)
@ -177,17 +178,10 @@ void addDependency(std::string path)
// we need to check if this library was already added to avoid duplicates
const int dep_amount = deps.size();
int start = 0;
int end = dep_amount;
// parallel_for(dep_amount, [&](int start, int end)
// {
for(int i=start; i<end; ++i)
{
if(dep.mergeIfSameAs(deps[i]))
return;
}
// pthread_exit(NULL);
// });
for(int n=0; n<dep_amount; n++)
{
if(dep.mergeIfSameAs(deps[n])) return;
}
if(!Settings::isPrefixBundled(dep.getPrefix())) return;
@ -205,7 +199,6 @@ void collectDependencies(std::string filename, std::vector<std::string>& lines)
if(output.find("can't open file")!=std::string::npos or output.find("No such file")!=std::string::npos or output.size()<1)
{
std::cerr << output << std::endl;
std::cerr << "Cannot find file " << filename << " to read its dependencies" << std::endl;
exit(1);
}
@ -225,6 +218,7 @@ void collectDependencies(std::string filename)
const int line_amount = lines.size();
int start = 0;
int end = line_amount;
std::cout << "collectDeps: # of lines: " << line_amount << std::endl;
// parallel_for(line_amount, [&](int start, int end)
// {
for(int i=start; i<end; ++i)
@ -258,6 +252,7 @@ void collectSubDependencies()
dep_amount = deps.size();
int start = 0;
int end = deps.size();
std::cout << "collectSubDeps: # of deps: " << dep_amount << std::endl;
// parallel_for(dep_amount, [&](int start, int end)
// {
for(int i=start; i<end; ++i)
@ -274,6 +269,7 @@ void collectSubDependencies()
const int line_amount = lines.size();
int s = 0;
int e = line_amount;
std::cout << "collectSubDeps: # of lines: " << line_amount << std::endl;
// parallel_for(line_amount, [&](int s, int e)
// {
for(int j=s; j<e; ++j)
@ -356,26 +352,32 @@ void doneWithDeps_go()
createDestDir();
// for(int n=0; n<dep_amount; n++)
parallel_for(dep_amount, [&](int start, int end)
{
std::cout << "donewithDeps_go: # of deps: " << dep_amount << std::endl;
int start = 0;
int end = dep_amount;
// parallel_for(dep_amount, [&](int start, int end)
// {
for(int i=start; i<end; ++i)
{
deps[i].copyYourself();
changeLibPathsOnFile(deps[i].getInstallPath());
fixRpathsOnFile(deps[i].getOriginalPath(), deps[i].getInstallPath());
}
});
// });
}
const int fileToFixAmount = Settings::fileToFixAmount();
parallel_for(fileToFixAmount, [&](int start, int end)
{
for(int i=start; i<end; ++i)
std::cout << "# of files to fix: " << fileToFixAmount << std::endl;
int s = 0;
int e = fileToFixAmount;
// parallel_for(fileToFixAmount, [&](int start, int end)
// {
for(int i=s; i<e; ++i)
{
changeLibPathsOnFile(Settings::fileToFix(i));
fixRpathsOnFile(Settings::fileToFix(i), Settings::fileToFix(i));
}
});
// });
}

View File

@ -154,13 +154,9 @@ int main (int argc, char * const argv[])
std::cout << "* Collecting dependencies"; fflush(stdout);
const int amount = Settings::fileToFixAmount();
int start = 0;
int end = amount;
// parallel_for(amount, [&](int start, int end)
// {
for(int i=start; i<end; ++i)
collectDependencies(Settings::fileToFix(i));
// });
std::cout << "# of files to fix: " << amount << std::endl;
for(int n=0; n<amount; n++)
collectDependencies(Settings::fileToFix(n));
collectSubDependencies();
doneWithDeps_go();