From 9d292f7e22e1af751918a5ed002a90b69adf9545 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Tue, 23 Jul 2024 07:12:00 +0530 Subject: solver_util -> jobid --- include/jobid.h | 16 ++++++++ include/queue.h | 1 - include/solver_util.h | 20 ---------- src/evanix.c | 1 - src/jobid.c | 80 +++++++++++++++++++++++++++++++++++++++ src/meson.build | 2 +- src/solver_util.c | 101 -------------------------------------------------- 7 files changed, 97 insertions(+), 124 deletions(-) create mode 100644 include/jobid.h delete mode 100644 include/solver_util.h create mode 100644 src/jobid.c delete mode 100644 src/solver_util.c diff --git a/include/jobid.h b/include/jobid.h new file mode 100644 index 0000000..980c85c --- /dev/null +++ b/include/jobid.h @@ -0,0 +1,16 @@ +#include + +#include "jobs.h" + +#ifndef SOLVER_UTIL_H + +struct jobid { + struct job **jobs; + size_t filled, size; +}; + +void jobid_free(struct jobid *jid); +int jobid_init(struct job_clist *q, struct jobid **jobid); + +#define SOLVER_UTIL_H +#endif diff --git a/include/queue.h b/include/queue.h index ca318cf..e6178e2 100644 --- a/include/queue.h +++ b/include/queue.h @@ -5,7 +5,6 @@ #include #include "jobs.h" -#include "solver_util.h" #ifndef QUEUE_H diff --git a/include/solver_util.h b/include/solver_util.h deleted file mode 100644 index 08f7f16..0000000 --- a/include/solver_util.h +++ /dev/null @@ -1,20 +0,0 @@ -#include - -#include "jobs.h" - -#ifndef SOLVER_UTIL_H - -struct jobid { - struct job **jobs; - size_t filled, size; - uint32_t *cost; - /* user directly asked for this to be built, not a transitively acquired - * dependency */ - bool *isdirect; -}; - -void jobid_free(struct jobid *jid); -int jobid_init(struct job_clist *q, struct jobid **job_ids); - -#define SOLVER_UTIL_H -#endif diff --git a/src/evanix.c b/src/evanix.c index 6721d4e..c75bd70 100644 --- a/src/evanix.c +++ b/src/evanix.c @@ -6,7 +6,6 @@ #include "evanix.h" #include "queue.h" #include "solver_greedy.h" -#include "solver_util.h" #include "util.h" static const char usage[] = diff --git a/src/jobid.c b/src/jobid.c new file mode 100644 index 0000000..d1ca8ab --- /dev/null +++ b/src/jobid.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include + +#include "jobs.h" +#include "jobid.h" +#include "util.h" + +static int dag_id_assign(struct job *j, struct jobid *jobid); + +static int dag_id_assign(struct job *j, struct jobid *jobid) +{ + size_t newsize; + void *ret; + + if (j->id >= 0) + return 0; + + for (size_t i = 0; i < j->deps_filled; i++) + return dag_id_assign(j->deps[i], jobid); + + if (jobid->size < jobid->filled) { + j->id = jobid->filled++; + jobid->jobs[j->id] = j; + return 0; + } + + newsize = jobid->size == 0 ? 2 : jobid->size * 2; + ret = realloc(jobid->jobs, newsize * sizeof(*jobid->jobs)); + if (ret == NULL) { + print_err("%s", strerror(errno)); + return -errno; + } + jobid->jobs = ret; + + j->id = jobid->filled++; + jobid->jobs[j->id] = j; + + return 0; +} + +void jobid_free(struct jobid *jid) +{ + free(jid->jobs); + free(jid); +} + +int jobid_init(struct job_clist *q, struct jobid **jobid) +{ + struct jobid *jid; + struct job *j; + int ret = 0; + + jid = malloc(sizeof(*jid)); + if (jid == NULL) { + print_err("%s", strerror(errno)); + return -errno; + } + jid->jobs = NULL; + jid->size = 0; + jid->filled = 0; + + CIRCLEQ_FOREACH (j, q, clist) { + ret = dag_id_assign(j, jid); + if (ret < 0) { + goto out_free_jid; + } + } + +out_free_jid: + if (ret < 0) { + free(jid->jobs); + free(jid); + } else { + *jobid = jid; + } + + return ret; +} diff --git a/src/meson.build b/src/meson.build index b908721..d4ccec2 100644 --- a/src/meson.build +++ b/src/meson.build @@ -7,7 +7,7 @@ e = executable( 'util.c', 'queue.c', 'build.c', - 'solver_util.c', + 'jobid.c', 'solver_greedy.c', ], diff --git a/src/solver_util.c b/src/solver_util.c deleted file mode 100644 index 5731c9a..0000000 --- a/src/solver_util.c +++ /dev/null @@ -1,101 +0,0 @@ -#include -#include -#include -#include - -#include "jobs.h" -#include "solver_util.h" -#include "util.h" - -static int dag_id_assign(struct job *j, struct jobid *jobid); - -static int dag_id_assign(struct job *j, struct jobid *jobid) -{ - size_t newsize; - void *ret; - - if (j->id >= 0) - return 0; - - for (size_t i = 0; i < j->deps_filled; i++) - return dag_id_assign(j->deps[i], jobid); - - if (jobid->size < jobid->filled) { - j->id = jobid->filled++; - jobid->jobs[j->id] = j; - return 0; - } - - newsize = jobid->size == 0 ? 2 : jobid->size * 2; - ret = realloc(jobid->jobs, newsize * sizeof(*jobid->jobs)); - if (ret == NULL) { - print_err("%s", strerror(errno)); - return -errno; - } - jobid->jobs = ret; - - j->id = jobid->filled++; - jobid->jobs[j->id] = j; - - return 0; -} - -void jobid_free(struct jobid *jid) -{ - free(jid->cost); - free(jid->isdirect); - free(jid->jobs); - free(jid); -} - -int jobid_init(struct job_clist *q, struct jobid **job_ids) -{ - struct jobid *jid; - struct job *j; - int ret = 0; - - jid = malloc(sizeof(*jid)); - if (jid == NULL) { - print_err("%s", strerror(errno)); - return -errno; - } - jid->jobs = NULL; - jid->cost = NULL; - jid->isdirect = NULL; - jid->size = 0; - jid->filled = 0; - - CIRCLEQ_FOREACH (j, q, clist) { - ret = dag_id_assign(j, jid); - if (ret < 0) { - goto out_free_jid; - } - } - - jid->isdirect = malloc(jid->filled * sizeof(*jid->isdirect)); - if (jid->isdirect == NULL) { - print_err("%s", strerror(errno)); - return -errno; - } - jid->cost = malloc(jid->filled * sizeof(*jid->cost)); - if (jid->cost == NULL) { - print_err("%s", strerror(errno)); - return -errno; - } - for (size_t i = 0; i < jid->filled; i++) { - jid->isdirect[i] = jid->jobs[i]->scheduled; - jid->cost[i] = 1; - } - -out_free_jid: - if (ret < 0) { - free(jid->cost); - free(jid->isdirect); - free(jid->jobs); - free(jid); - } else { - *job_ids = jid; - } - - return ret; -} -- cgit v1.2.3