1 From 513200cf76758de4668312c628d6362bdabfaf4b Mon Sep 17 00:00:00 2001
2 From: Alexander Kanavin <alex.kanavin@gmail.com>
3 Date: Thu, 25 May 2017 19:30:20 +0300
4 Subject: [PATCH 1/3] Run binary package creation via thread pools.
6 Upstream-Status: Submitted [https://github.com/rpm-software-management/rpm/pull/226]
7 Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
10 build/pack.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++-----------
12 2 files changed, 70 insertions(+), 14 deletions(-)
14 diff --git a/build/pack.c b/build/pack.c
15 index ccfd614cc..ed5b9ab4e 100644
18 @@ -616,25 +616,78 @@ static rpmRC packageBinary(rpmSpec spec, Package pkg, const char *cookie, int ch
22 -rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
23 +struct binaryPackageTaskData
29 + struct binaryPackageTaskData *next;
32 +static struct binaryPackageTaskData* runBinaryPackageTasks(rpmSpec spec, const char *cookie, int cheating)
34 + struct binaryPackageTaskData *tasks = NULL;
35 + struct binaryPackageTaskData *task = NULL;
36 + struct binaryPackageTaskData *prev = NULL;
38 + for (Package pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
39 + task = rcalloc(1, sizeof(*task));
41 + if (pkg == spec->packages) {
42 + // the first package needs to be processed ahead of others, as they copy
43 + // changelog data from it, and so otherwise data races would happen
44 + task->result = packageBinary(spec, pkg, cookie, cheating, &(task->filename));
45 + rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename);
54 + #pragma omp parallel
56 + // re-declaring task variable is necessary, or older gcc versions will produce code that segfaults
57 + for (struct binaryPackageTaskData *task = tasks; task != NULL; task = task->next) {
61 + task->result = packageBinary(spec, task->pkg, cookie, cheating, &(task->filename));
62 + rpmlog(RPMLOG_NOTICE, _("Finished binary package job, result %d, filename %s\n"), task->result, task->filename);
69 +static void freeBinaryPackageTasks(struct binaryPackageTaskData* tasks)
71 + while (tasks != NULL) {
72 + struct binaryPackageTaskData* next = tasks->next;
73 + rfree(tasks->filename);
79 +rpmRC packageBinaries(rpmSpec spec, const char *cookie, int cheating)
83 - for (pkg = spec->packages; pkg != NULL; pkg = pkg->next) {
85 - rc = packageBinary(spec, pkg, cookie, cheating, &fn);
86 - if (rc == RPMRC_OK) {
87 - rstrcat(&pkglist, fn);
88 - rstrcat(&pkglist, " ");
91 - if (rc != RPMRC_OK) {
92 - pkglist = _free(pkglist);
95 + struct binaryPackageTaskData *tasks = runBinaryPackageTasks(spec, cookie, cheating);
97 + for (struct binaryPackageTaskData *task = tasks; task != NULL; task = task->next) {
98 + if (task->result == RPMRC_OK) {
99 + rstrcat(&pkglist, task->filename);
100 + rstrcat(&pkglist, " ");
103 + freeBinaryPackageTasks(tasks);
107 + freeBinaryPackageTasks(tasks);
109 /* Now check the package set if enabled */
110 if (pkglist != NULL) {
111 diff --git a/configure.ac b/configure.ac
112 index a506ec819..59fa0acaf 100644
115 @@ -17,6 +17,9 @@ AC_DISABLE_STATIC
120 +RPMCFLAGS="$OPENMP_CFLAGS $RPMCFLAGS"
122 dnl Checks for programs.