From 46de53cd55267cdb22e1cdeca4bbbe0b0b699a5b Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Fri, 23 Apr 2021 18:30:16 +0200 Subject: [PATCH] MODULE REPO: Don't exit after updating the db (loose workers) --- .clang-format | 5 ++++- inc/lektor/common.h | 5 ++--- src/module/module_repo.c | 12 ++++++------ src/module/worker.c | 8 +++++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.clang-format b/.clang-format index 712a12ff..6ba67db5 100644 --- a/.clang-format +++ b/.clang-format @@ -58,7 +58,10 @@ CommentPragmas: '^ KEEP pragma:' ForEachMacros: - 'for_each' - + - 'FOR_EACH' + - 'FOR_EVER' + - 'FOR_EVER_IF' + - 'FOR_EVER_UNTIL' IncludeCategories: - Regex: '.*' diff --git a/inc/lektor/common.h b/inc/lektor/common.h index d26a4d40..d6dd82e2 100644 --- a/inc/lektor/common.h +++ b/inc/lektor/common.h @@ -60,12 +60,11 @@ extern EXIT_FUNCTION ___not_implemented(const char *func, char *file, int line); #define FUNCTION_POINTER(func) ((void (*)(void))(func)) #define FOR_EVER for (;;) #define FOR_EVER_IF(expr) \ - FOR_EVER \ - { \ + FOR_EVER { \ if (!(expr)) \ break; \ } -#define FOR_EVER_UNTIL(expr) FOR_EVER_IF(!(expr)) +#define FOR_EVER_UNTIL(expr) FOR_EVER_IF (!(expr)) /* Custom defined assert. */ extern void (*___lkt_assert)(const char *file, int line, const char *func, const char *msg); diff --git a/src/module/module_repo.c b/src/module/module_repo.c index f2edfdaa..71922468 100644 --- a/src/module/module_repo.c +++ b/src/module/module_repo.c @@ -516,7 +516,7 @@ ___worker_update(void UNUSED *worker, void *___repo) LOG_INFO("REPO", "Download kara list from %s (%s)", repo->name, repo->get_all_json); if (___json_dl(repo->get_all_json, &json)) { LOG_ERROR("REPO", "Failed to get json, possibly no internet connexion or repo is down"); - pthread_exit(NULL); + return NULL; } int ret = ___handle_got_json(repo->db, repo, json); @@ -540,7 +540,7 @@ ___worker_update(void UNUSED *worker, void *___repo) end_no_lock: lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_FINISHED); - pthread_exit(NULL); + return NULL; } static void * @@ -552,7 +552,7 @@ ___worker_rescan(void UNUSED *worker, void *___repo) if (!database_config_get(repo->db, "database", "kara_dir", kara_prefix, LKT_LINE_MAX)) { LOG_ERROR("REPO", "Failed to get kara prefix from config"); - pthread_exit(NULL); + return NULL; } GOTO_IF(pthread_mutex_lock(&(repo->mtx)), "Failed to lock", end_no_lock); @@ -569,7 +569,7 @@ ___worker_rescan(void UNUSED *worker, void *___repo) end_no_lock: lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_FINISHED); - pthread_exit(NULL); + return NULL; } static int @@ -688,7 +688,7 @@ ___worker_import_favorites(void *worker, void *___repo) LOG_INFO("REPO", "Download fav lists: %s", repo->get_fav_json); if (___json_dl(repo->get_fav_json, &json)) { LOG_ERROR("REPO", "Failed to get json, possibly no internet connexion or repo is down"); - pthread_exit(NULL); + return NULL; } size_t len = json_parse_get_count(json, 2); @@ -711,7 +711,7 @@ ___worker_import_favorites(void *worker, void *___repo) end_no_lock: lkt_queue_send(repo->queue, LKT_EVENT_DB_UPDATING, LKT_DB_UPDATING_FINISHED); - pthread_exit(NULL); + return NULL; } /*********************************************** diff --git a/src/module/worker.c b/src/module/worker.c index e2f6463f..509f6a79 100644 --- a/src/module/worker.c +++ b/src/module/worker.c @@ -13,7 +13,7 @@ ___worker_thread(void *___pool) volatile struct worker_pool *pool = (volatile struct worker_pool *)___pool; volatile void *volatile arg; worker_function func; - for (;;) { + FOR_EVER { assert(!pthread_mutex_lock((pthread_mutex_t *)&pool->lock)); if (pool->len) { --(pool->len); @@ -31,7 +31,9 @@ ___worker_thread(void *___pool) } assert(!pthread_mutex_unlock((pthread_mutex_t *)&pool->lock)); + LOG_INFO("WORKER", "Picked up a function"); func(___pool, (void *)arg); + LOG_INFO("WORKER", "Finished work for a function"); assert(!pthread_mutex_lock((pthread_mutex_t *)&pool->lock)); --(pool->thread_working); @@ -142,8 +144,8 @@ void worker_pool_waitall(struct worker_pool *pool) { /* No lock, nothing, just test and yield */ - FOR_EVER_IF(pool->len) - sched_yield(); + FOR_EVER_IF (pool->len) + sched_yield(); } size_t -- GitLab