Skip to content

Commit

Permalink
Run binary package creation via thread pools.
Browse files Browse the repository at this point in the history
  • Loading branch information
kanavin committed Jun 9, 2017
1 parent 826d853 commit e0a2f0c
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
80 changes: 66 additions & 14 deletions build/pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,25 +707,77 @@ static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int ch
return rc;
}

rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
struct binaryPackageTaskData
{
rpmRC rc;
Package pkg;
char *filename;
rpmRC result;
struct binaryPackageTaskData *next;
};

static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const char *cookie, int cheating)
{
struct binaryPackageTaskData *tasks = NULL;
struct binaryPackageTaskData *task = NULL;
struct binaryPackageTaskData *prev = NULL;

for (Package pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
task = rcalloc(1, sizeof(*task));
task->pkg = pkg;
if (pkg == spec->packages) {
// the first package needs to be processed ahead of others, as they copy
// changelog data from it, and so otherwise data races would happen
task->result = packageBinary(spec, pkg, cookie, cheating, &(task->filename));
rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename);
tasks = task;
}
if (prev != NULL) {
prev->next = task;
}
prev = task;
}

#pragma omp parallel
#pragma omp single
for (task = tasks; task != NULL; task = task->next) {
if (task != tasks)
#pragma omp task
{
task->result = packageBinary(spec, task->pkg, cookie, cheating, &(task->filename));
rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename);
}
}

return tasks;
}

static void freeBinaryPackageTasks(struct binaryPackageTaskData* tasks)
{
while (tasks != NULL) {
struct binaryPackageTaskData* next = tasks->next;
rfree(tasks->filename);
rfree(tasks);
tasks = next;
}
}

rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
{
char *pkglist = NULL;

for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
char *fn = NULL;
rc = packageBinary(spec, pkg, cookie, cheating, &fn);
if (rc == RPMRC_OK) {
rstrcat(&pkglist, fn);
rstrcat(&pkglist, " ");
}
free(fn);
if (rc != RPMRC_OK) {
pkglist = _free(pkglist);
return rc;
}
struct binaryPackageTaskData *tasks = runBinaryPackageTasks(spec, cookie, cheating);

for (struct binaryPackageTaskData *task = tasks; task != NULL; task = task->next) {
if (task->result == RPMRC_OK) {
rstrcat(&pkglist, task->filename);
rstrcat(&pkglist, " ");
} else {
_free(pkglist);
freeBinaryPackageTasks(tasks);
return RPMRC_FAIL;
}
}
freeBinaryPackageTasks(tasks);

/* Now check the package set if enabled */
if (pkglist != NULL) {
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ AC_DISABLE_STATIC

PKG_PROG_PKG_CONFIG

AC_OPENMP
RPMCFLAGS="$OPENMP_CFLAGS $RPMCFLAGS"

dnl Checks for programs.
AC_PROG_CXX
AC_PROG_AWK
Expand Down

0 comments on commit e0a2f0c

Please sign in to comment.