aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/jobs.h4
-rw-r--r--include/queue.h2
-rw-r--r--src/jobs.c1
-rw-r--r--src/queue.c25
4 files changed, 32 insertions, 0 deletions
diff --git a/include/jobs.h b/include/jobs.h
index 54152cf..41d8adf 100644
--- a/include/jobs.h
+++ b/include/jobs.h
@@ -1,4 +1,5 @@
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
#include <sys/queue.h>
@@ -26,6 +27,8 @@ struct job {
/* solver */
ssize_t id;
+ uint64_t age;
+ bool stale;
};
CIRCLEQ_HEAD(job_clist, job);
@@ -44,6 +47,7 @@ int jobs_init(FILE **stream, char *expr);
void job_free(struct job *j);
int job_parents_list_insert(struct job *job, struct job *parent);
void job_deps_list_rm(struct job *job, struct job *dep);
+void job_stale_set(struct job *job);
#define JOBS_H
#endif
diff --git a/include/queue.h b/include/queue.h
index dd7e4db..c81f062 100644
--- a/include/queue.h
+++ b/include/queue.h
@@ -1,4 +1,5 @@
#include <pthread.h>
+#include <stdint.h>
#include <search.h>
#include <semaphore.h>
#include <sys/queue.h>
@@ -21,6 +22,7 @@ struct queue {
sem_t sem;
queue_state_t state;
pthread_mutex_t mutex;
+ uint64_t age;
};
struct queue_thread {
diff --git a/src/jobs.c b/src/jobs.c
index 95566cb..aeac2fa 100644
--- a/src/jobs.c
+++ b/src/jobs.c
@@ -370,6 +370,7 @@ static int job_new(struct job **j, char *name, char *drv_path, char *attr,
job->scheduled = false;
job->stale = false;
job->id = -1;
+ job->age = 0;
job->outputs_size = 0;
job->outputs_filled = 0;
diff --git a/src/queue.c b/src/queue.c
index 655822e..148ca9a 100644
--- a/src/queue.c
+++ b/src/queue.c
@@ -51,6 +51,30 @@ static int queue_dag_isolate(struct job *job, struct job *keep_parent,
return 0;
}
+/* remove a node along with all it's ancestors recursively */
+int queue_ancestors_rm(struct job *job, struct job_clist *jobs,
+ struct htab *htab)
+{
+ struct job *j;
+ int ret;
+
+ job_stale_set(job);
+ CIRCLEQ_FOREACH(j, jobs, clist) {
+ if (j->stale == false)
+ continue;
+
+ ret = queue_dag_isolate(j, NULL, jobs, htab);
+ if (ret < 0)
+ return ret;
+
+ job_free(j);
+ /* we might have removed j->clist.cqe_next */
+ j = jobs->cqh_last;
+ }
+
+ return 0;
+}
+
void *queue_thread_entry(void *queue_thread)
{
struct queue_thread *qt = queue_thread;
@@ -221,6 +245,7 @@ int queue_thread_new(struct queue_thread **queue_thread, FILE *stream)
ret = -errno;
goto out_free_qt;
}
+ qt->queue->age = 0;
qt->queue->jobid = NULL;
qt->queue->state = Q_SEM_WAIT;
ret = sem_init(&qt->queue->sem, 0, 0);