From: Alberto Leiva Popper Date: Thu, 6 Mar 2025 22:15:32 +0000 (-0600) Subject: Rename task states, to match documentation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=834a5e1310aefc44de6e970b23a7e81acc3b2859;p=thirdparty%2FFORT-validator.git Rename task states, to match documentation --- diff --git a/src/cache.c b/src/cache.c index e0b6b4a3..cabd0269 100644 --- a/src/cache.c +++ b/src/cache.c @@ -900,7 +900,7 @@ do_refresh(struct cache_table *tbl, char const *uri, struct cache_node **result) /* node->state is guaranteed to be DLS_FRESH at this point. */ if (downloaded) /* Kickstart tasks that fell into DLS_ONGOING */ - task_wakeup_busy(); + task_wakeup_dormants(); if (node->dlerr != 0) { pr_val_debug("Refresh failed."); diff --git a/src/object/tal.c b/src/object/tal.c index f8d01321..cb199627 100644 --- a/src/object/tal.c +++ b/src/object/tal.c @@ -169,6 +169,7 @@ traverse_tal(char const *tal_path, void *arg) /* Online attempts */ ARRAYLIST_FOREACH(&tal.urls, url) { map.url = *url; + // XXX if this is rsync, it seems this will queue and fail map.path = cache_refresh_by_url(*url); if (!map.path) continue; @@ -205,7 +206,7 @@ pick_up_work(void *arg) while ((task = task_dequeue(task)) != NULL) { if (certificate_traverse(task->ca) == EBUSY) { - task_requeue_busy(task); + task_requeue_dormant(task); task = NULL; } } diff --git a/src/task.c b/src/task.c index 6fab1945..a4a2b758 100644 --- a/src/task.c +++ b/src/task.c @@ -9,11 +9,14 @@ STAILQ_HEAD(validation_tasks, validation_task); /* Queued, not yet claimed tasks */ -static struct validation_tasks tasks; +static struct validation_tasks waiting; /* Queued, but not yet available for claiming */ -static struct validation_tasks busy; -/* Active tasks (length(@tasks) + length(@busy) + number of running tasks) */ -static int active; +static struct validation_tasks dormant; +/* + * Total currently existing tasks + * (length(@waiting) + length(@dormant) + total active tasks) + */ +static int ntasks; static bool enabled = true; @@ -30,9 +33,9 @@ task_free(struct validation_task *task) void task_setup(void) { - STAILQ_INIT(&tasks); - STAILQ_INIT(&busy); - active = 0; + STAILQ_INIT(&waiting); + STAILQ_INIT(&dormant); + ntasks = 0; enabled = true; panic_on_fail(pthread_mutex_init(&lock, NULL), "pthread_mutex_init"); panic_on_fail(pthread_cond_init(&awakener, NULL), "pthread_cond_init"); @@ -54,9 +57,9 @@ static void cleanup(void) { enabled = false; - active = 0; - cleanup_tasks(&tasks); - cleanup_tasks(&busy); + ntasks = 0; + cleanup_tasks(&waiting); + cleanup_tasks(&dormant); } void @@ -84,6 +87,7 @@ task_teardown(void) /* * Defers a task for later. * Call task_wakeup() once you've queued all your tasks. + * Returns number of deferred tasks. */ unsigned int task_enqueue(struct cache_mapping *map, struct rpki_certificate *parent) @@ -104,9 +108,9 @@ task_enqueue(struct cache_mapping *map, struct rpki_certificate *parent) mutex_lock(&lock); if (enabled) { - STAILQ_INSERT_TAIL(&tasks, task, lh); + STAILQ_INSERT_TAIL(&waiting, task, lh); task = NULL; - active++; + ntasks++; } mutex_unlock(&lock); @@ -118,12 +122,13 @@ task_enqueue(struct cache_mapping *map, struct rpki_certificate *parent) return 1; } +/* Steals ownership of @task. */ void -task_requeue_busy(struct validation_task *task) +task_requeue_dormant(struct validation_task *task) { mutex_lock(&lock); if (enabled) { - STAILQ_INSERT_TAIL(&busy, task, lh); + STAILQ_INSERT_TAIL(&dormant, task, lh); task = NULL; } mutex_unlock(&lock); @@ -132,7 +137,7 @@ task_requeue_busy(struct validation_task *task) task_free(task); /* Couldn't queue */ } -/* Wakes up threads currently waiting for tasks. */ +/* Wakes up all sleeping task threads. */ void task_wakeup(void) { @@ -142,11 +147,12 @@ task_wakeup(void) mutex_unlock(&lock); } +/* Upgrades all dormant tasks, and wakes up all sleeping task threads. */ void -task_wakeup_busy(void) +task_wakeup_dormants(void) { mutex_lock(&lock); - STAILQ_CONCAT(&tasks, &busy); + STAILQ_CONCAT(&waiting, &dormant); panic_on_fail(pthread_cond_broadcast(&awakener), "pthread_cond_broadcast"); mutex_unlock(&lock); @@ -156,9 +162,10 @@ task_wakeup_busy(void) * Frees the @prev previous task, and returns the next one. * * If no task is available yet, will sleep until someone calls task_wakeup() or - * task_wakeup_busy(). + * task_wakeup_dormants(). * If all the tasks are done, returns NULL. * + * Steals ownership of @prev. * Assumes at least one task has been queued before the first dequeue. */ struct validation_task * @@ -178,17 +185,17 @@ task_dequeue(struct validation_task *prev) goto end; if (prev) { - active--; - if (active < 0) - pr_crit("active < 0: %d", active); + ntasks--; + if (ntasks < 0) + pr_crit("active < 0: %d", ntasks); } - while (active > 0) { - pr_op_debug("task_dequeue(): %u tasks active.", active); + while (ntasks > 0) { + pr_op_debug("task_dequeue(): %u existing tasks.", ntasks); - task = STAILQ_FIRST(&tasks); + task = STAILQ_FIRST(&waiting); if (task != NULL) { - STAILQ_REMOVE_HEAD(&tasks, lh); + STAILQ_REMOVE_HEAD(&waiting, lh); mutex_unlock(&lock); pr_op_debug("task_dequeue(): Claimed task '%s'.", task->ca->map.url); diff --git a/src/task.h b/src/task.h index 356cf53f..b31251cc 100644 --- a/src/task.h +++ b/src/task.h @@ -17,9 +17,9 @@ void task_stop(void); void task_teardown(void); unsigned int task_enqueue(struct cache_mapping *, struct rpki_certificate *); -void task_requeue_busy(struct validation_task *); +void task_requeue_dormant(struct validation_task *); void task_wakeup(void); -void task_wakeup_busy(void); +void task_wakeup_dormants(void); struct validation_task *task_dequeue(struct validation_task *); #endif /* SRC_TASK_H_ */ diff --git a/test/cache_test.c b/test/cache_test.c index d63b5980..cbaec3ac 100644 --- a/test/cache_test.c +++ b/test/cache_test.c @@ -53,7 +53,7 @@ rsync_download(char const *url, char const *path) } MOCK_VOID(__delete_node_cb, struct cache_node const *node) -MOCK_VOID(task_wakeup_busy, void) +MOCK_VOID(task_wakeup_dormants, void) static asn_dec_rval_t dummy = { 0 }; __MOCK_ABORT(ber_check_tags, asn_dec_rval_t, dummy, const asn_codec_ctx_t *ctx, const asn_TYPE_descriptor_t *td, asn_struct_ctx_t *opt_ctx, diff --git a/test/task_test.c b/test/task_test.c index 5df2f53b..bdd0d839 100644 --- a/test/task_test.c +++ b/test/task_test.c @@ -139,7 +139,7 @@ struct test_task { static STAILQ_HEAD(test_task_list, test_task) test_tasks; static pthread_mutex_t test_tasks_lock = PTHREAD_MUTEX_INITIALIZER; -static bool return_busy; +static bool return_dormant; static void populate_test_tasks(void) @@ -188,7 +188,7 @@ certificate_traverse_mock(struct rpki_certificate *ca, int thid) if (n != 0) task_wakeup(); - if (return_busy && (rand() & 3) == 0) + if (return_dormant && (rand() & 3) == 0) return EBUSY; /* Return "busy" 25% of the time */ return 0; @@ -210,7 +210,7 @@ user_thread(void *arg) if (certificate_traverse_mock(task->ca, thid) == EBUSY) { printf("+ th%d: Requeuing '%s'\n", thid, task->ca->map.url); - task_requeue_busy(task); + task_requeue_dormant(task); task = NULL; } } @@ -241,7 +241,7 @@ run_threads(void) START_TEST(test_queue_multiuser) { - return_busy = false; + return_dormant = false; task_setup(); task_start(); @@ -255,20 +255,20 @@ START_TEST(test_queue_multiuser) END_TEST static void * -release_busies(void *arg) +upgrade_dormants(void *arg) { unsigned int i; for (i = 0; i < 2; i++) { sleep(1); - printf("Waking up busy tasks!\n"); - task_wakeup_busy(); + printf("Upgrading dormant tasks!\n"); + task_wakeup_dormants(); } sleep(1); - return_busy = false; - printf("Waking up busy tasks for the last time!\n"); - task_wakeup_busy(); + return_dormant = false; + printf("Upgrading dormant tasks for the last time!\n"); + task_wakeup_dormants(); return NULL; } @@ -277,12 +277,12 @@ START_TEST(test_queue_multiuser_busy) { pthread_t thr; - return_busy = true; + return_dormant = true; task_setup(); task_start(); - ck_assert_int_eq(0, pthread_create(&thr, NULL, release_busies, NULL)); + ck_assert_int_eq(0, pthread_create(&thr, NULL, upgrade_dormants, NULL)); populate_test_tasks(); run_threads();