aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2024-06-30 12:59:44 +0530
committersinanmohd <sinan@sinanmohd.com>2024-06-30 14:08:17 +0530
commit96647a48d9ddf12e239d99af514a743721c06f84 (patch)
tree4705b5d215fcb12389843c7da5c32233a368ccad
parentbf2d66357b9135442f9dec277678b0597abc1d15 (diff)
solver_util/jobid: build cost and isdirect
-rw-r--r--include/queue.h2
-rw-r--r--include/solver_util.h13
-rw-r--r--src/queue.c2
-rw-r--r--src/solver_util.c73
4 files changed, 63 insertions, 27 deletions
diff --git a/include/queue.h b/include/queue.h
index fee5bb3..dd7e4db 100644
--- a/include/queue.h
+++ b/include/queue.h
@@ -17,7 +17,7 @@ typedef enum {
struct queue {
struct job_clist jobs;
struct htab *htab;
- struct job_ids *job_ids;
+ struct jobid *jobid;
sem_t sem;
queue_state_t state;
pthread_mutex_t mutex;
diff --git a/include/solver_util.h b/include/solver_util.h
index 99d5fcd..5c5f5d2 100644
--- a/include/solver_util.h
+++ b/include/solver_util.h
@@ -1,11 +1,20 @@
+#include <stdint.h>
+
#include "jobs.h"
#ifndef SOLVER_UTIL_H
-struct job_ids {
+struct jobid {
struct job **jobs;
- ssize_t filled, size;
+ size_t filled, size;
+ uint32_t *cost;
+ /* user directly asked for this to be build, 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/queue.c b/src/queue.c
index 75a3e14..655822e 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -221,7 +221,7 @@ int queue_thread_new(struct queue_thread **queue_thread, FILE *stream)
ret = -errno;
goto out_free_qt;
}
- qt->queue->job_ids = NULL;
+ qt->queue->jobid = NULL;
qt->queue->state = Q_SEM_WAIT;
ret = sem_init(&qt->queue->sem, 0, 0);
if (ret < 0) {
diff --git a/src/solver_util.c b/src/solver_util.c
index 9efb65a..950c176 100644
--- a/src/solver_util.c
+++ b/src/solver_util.c
@@ -7,7 +7,7 @@
#include "solver_util.h"
#include "util.h"
-static int dag_id_assign(struct job *j, struct job_ids *job_ids)
+static int dag_id_assign(struct job *j, struct jobid *jobid)
{
size_t newsize;
void *ret;
@@ -16,56 +16,83 @@ static int dag_id_assign(struct job *j, struct job_ids *job_ids)
return 0;
for (size_t i = 0; i < j->deps_filled; i++)
- return dag_id_assign(j->deps[i], job_ids);
+ return dag_id_assign(j->deps[i], jobid);
- if (job_ids->size < job_ids->filled) {
- j->id = job_ids->filled++;
- job_ids->jobs[j->id] = j;
+ if (jobid->size < jobid->filled) {
+ j->id = jobid->filled++;
+ jobid->jobs[j->id] = j;
return 0;
}
- newsize = job_ids->size == 0 ? 2 : job_ids->size * 2;
- ret = realloc(job_ids->jobs, newsize * sizeof(*job_ids->jobs));
+ 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;
}
- job_ids->jobs = ret;
+ jobid->jobs = ret;
- j->id = job_ids->filled++;
- job_ids->jobs[j->id] = j;
+ j->id = jobid->filled++;
+ jobid->jobs[j->id] = j;
return 0;
}
-int queue_id_assign(struct job_clist *q, struct job_ids **job_ids)
+void jobid_free(struct jobid *jid)
{
- struct job_ids *ji;
+ 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;
- ji = malloc(sizeof(*ji));
- if (ji == NULL) {
+ jid = malloc(sizeof(*jid));
+ if (jid == NULL) {
print_err("%s", strerror(errno));
return -errno;
}
- ji->jobs = NULL;
- ji->size = 0;
- ji->filled = 0;
+ 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, ji);
+ ret = dag_id_assign(j, jid);
if (ret < 0) {
- goto out_free_js;
+ goto out_free_jid;
}
}
-out_free_js:
+ 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(ji->jobs);
- free(ji);
+ free(jid->cost);
+ free(jid->isdirect);
+ free(jid->jobs);
+ free(jid);
} else {
- *job_ids = ji;
+ *job_ids = jid;
}
return ret;