From c8b3ed01a41c0215a4a33ce8468b162463129600 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Mon, 31 Mar 2025 19:16:50 -0400 Subject: Overall style change, small fixes - Tweak sink switch_to() order. Signed-off-by: Andrew Opalach --- src/util/color_palette.c | 23 +++++----- src/util/queue.h | 110 ++++++++++++++++++++++------------------------- 2 files changed, 63 insertions(+), 70 deletions(-) (limited to 'src/util') diff --git a/src/util/color_palette.c b/src/util/color_palette.c index 9cfdf32..d386858 100644 --- a/src/util/color_palette.c +++ b/src/util/color_palette.c @@ -1,3 +1,4 @@ +#define AL_LOG_SECTION "color_palette" #include #include "color_palette.h" @@ -41,14 +42,14 @@ bool camu_color_palette_init(str *path) return false; } - str s; - nn_file_read_as_str(&file, &s); + str buffer; + nn_file_read_as_str(&file, &buffer); nn_file_close(&file); json_error_t error; - json_t *root = json_loadb(s.data, s.length, 0, &error); - al_str_free(&s); + json_t *root = json_loadb(buffer.data, buffer.length, 0, &error); + al_str_free(&buffer); if (!root) { - al_log_error("color_palette", "Failed to load %.*s as a json (%s).", al_str_fmt(path), error.text); + error("Failed to load %.*s as a json (%s).", al_str_x(path), error.text); return false; } @@ -56,14 +57,14 @@ bool camu_color_palette_init(str *path) json_t *special = json_object_get(root, "special"); if (!special) { - al_log_error("color_palette", "\"special\" field missing from the color palette."); + error("\"special\" field missing from the color palette."); parsed = false; goto out; } json_t *colors = json_object_get(root, "colors"); if (!colors) { - al_log_error("color_palette", "\"colors\" field missing from the color palette."); + error("\"colors\" field missing from the color palette."); parsed = false; goto out; } @@ -77,7 +78,7 @@ bool camu_color_palette_init(str *path) for (u32 i = 0; i < ARRAY_SIZE(special_colors); i++) { object = json_object_get(special, special_colors[i]); if (!object) { - al_log_error("color_palette", "Couldn't find special color: %s.", special_colors[i]); + error("Couldn't find special color: %s.", special_colors[i]); return false; } color = json_string_value(object); @@ -86,14 +87,14 @@ bool camu_color_palette_init(str *path) if (!to_long_error) { global_color_palette.colors[i] = value; } else { - al_log_warn("color_palette", "%s is not a valid hex color.", normal_colors[i]); + warn("%s is not a valid hex color.", normal_colors[i]); } } for (u32 i = 0; i < ARRAY_SIZE(normal_colors); i++) { object = json_object_get(colors, normal_colors[i]); if (!object) { - al_log_error("color_palette", "Couldn't find color: %s.", normal_colors[i]); + error("Couldn't find color: %s.", normal_colors[i]); return false; } color = json_string_value(object); @@ -102,7 +103,7 @@ bool camu_color_palette_init(str *path) if (!to_long_error) { global_color_palette.colors[i + 2] = value; } else { - al_log_warn("color_palette", "%s is not a valid hex color.", normal_colors[i]); + warn("%s is not a valid hex color.", normal_colors[i]); } } diff --git a/src/util/queue.h b/src/util/queue.h index d103831..17880e0 100644 --- a/src/util/queue.h +++ b/src/util/queue.h @@ -9,62 +9,54 @@ struct nn_mutex mutex; \ } -#define camu_queue_lock(q) \ -AL_MACRO_WRAP \ -{ \ - nn_mutex_lock(&(q).mutex); \ -} AL_MACRO_END - -#define camu_queue_unlock(q) \ -AL_MACRO_WRAP \ -{ \ - nn_mutex_unlock(&(q).mutex); \ -} AL_MACRO_END - -#define camu_queue_count(q, r) \ -AL_MACRO_WRAP \ -{ \ - nn_mutex_lock(&(q).mutex); \ - r = (q).a.count; \ - nn_mutex_unlock(&(q).mutex); \ -} AL_MACRO_END - -#define camu_queue_init(q) \ -AL_MACRO_WRAP \ -{ \ - al_array_init((q).a); \ - nn_mutex_init(&(q).mutex); \ -} AL_MACRO_END - -#define camu_queue_push(q, item) \ -AL_MACRO_WRAP \ -{ \ - nn_mutex_lock(&(q).mutex); \ - al_array_push((q).a, item); \ - nn_mutex_unlock(&(q).mutex); \ -} AL_MACRO_END - -#define camu_queue_pop(q, r) \ -AL_MACRO_WRAP \ -{ \ - nn_mutex_lock(&(q).mutex); \ - al_array_pop_at((q).a, 0, r); \ - nn_mutex_unlock(&(q).mutex); \ -} AL_MACRO_END - -#define camu_queue_try_pop(q, s, r) \ -AL_MACRO_WRAP \ -{ \ - nn_mutex_lock(&(q).mutex); \ - if ((s = (q).a.count) > 0) { \ - al_array_pop_at((q).a, 0, r); \ - } \ - nn_mutex_unlock(&(q).mutex); \ -} AL_MACRO_END - -#define camu_queue_free(q) \ -AL_MACRO_WRAP \ -{ \ - nn_mutex_destroy(&(q).mutex); \ - al_array_free((q).a); \ -} AL_MACRO_END +#define camu_queue_lock(q) \ + do { \ + nn_mutex_lock(&(q).mutex); \ + } while (0) + +#define camu_queue_unlock(q) \ + do { \ + nn_mutex_unlock(&(q).mutex); \ + } while (0) + +#define camu_queue_count(q, r) \ + do { \ + nn_mutex_lock(&(q).mutex); \ + r = (q).a.count; \ + nn_mutex_unlock(&(q).mutex); \ + } while (0) + +#define camu_queue_init(q) \ + do { \ + al_array_init((q).a); \ + nn_mutex_init(&(q).mutex); \ + } while (0) + +#define camu_queue_push(q, item) \ + do { \ + nn_mutex_lock(&(q).mutex); \ + al_array_push((q).a, item); \ + nn_mutex_unlock(&(q).mutex); \ + } while (0) + +#define camu_queue_pop(q, r) \ + do { \ + nn_mutex_lock(&(q).mutex); \ + al_array_pop_at((q).a, 0, r); \ + nn_mutex_unlock(&(q).mutex); \ + } while (0) + +#define camu_queue_try_pop(q, s, r) \ + do { \ + nn_mutex_lock(&(q).mutex); \ + if ((s = (q).a.count) > 0) { \ + al_array_pop_at((q).a, 0, r); \ + } \ + nn_mutex_unlock(&(q).mutex); \ + } while (0) + +#define camu_queue_free(q) \ + do { \ + nn_mutex_destroy(&(q).mutex); \ + al_array_free((q).a); \ + } while (0) -- cgit v1.2.3-101-g0448