diff --git a/.clang-format b/.clang-format index 712a12ff38706936e88e98d152a67aca1ec3414c..6ba67db58dcae48b7df410b5f441f625a8809aec 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 d26a4d400f63191dcb0b1c782d4b27a247dc9283..d6dd82e20947b40a980d71dbd004e69ce44246ce 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 f2edfdaabe6f892aace1223a92f74e328b495f42..71922468464e8cdaf59d0792afb96b524e9d6d10 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 e2f6463f89f4cd01f708fa2c604260ed2eec8dc6..509f6a7964c695b2df5e1e2eb7b164e99eab4c34 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