From c531795b8372eb0e69aa874476f3e96cd7c09dfc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 29 Jul 2019 20:13:26 +0200 Subject: wip: initial multithreaded renderer --- config.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index 707f7d93..dda3c635 100644 --- a/config.c +++ b/config.c @@ -107,26 +107,28 @@ get_config_path(void) } static bool -str_to_color(const char *s, uint32_t *color, const char *path, int lineno) +str_to_ulong(const char *s, int base, unsigned long *res) { if (s == NULL) return false; errno = 0; char *end = NULL; - unsigned long res = strtoul(s, &end, 16); - if (errno != 0) { - LOG_ERRNO("%s:%d: invalid color: %s", path, lineno, s); - return false; - } + *res = strtoul(s, &end, base); + return errno == 0 && *end == '\0'; +} - if (*end != '\0') { - LOG_ERR("%s:%d: invalid color: %s", path, lineno, s); +static bool +str_to_color(const char *s, uint32_t *color, const char *path, int lineno) +{ + unsigned long value; + if (!str_to_ulong(s, 16, &value)) { + LOG_ERRNO("%s:%d: invalid color: %s", path, lineno, s); return false; } - *color = res & 0xffffff; + *color = value & 0xffffff; return true; } @@ -149,6 +151,15 @@ parse_section_main(const char *key, const char *value, struct config *conf, conf->font = strdup(value); } + else if (strcmp(key, "workers") == 0) { + unsigned long count; + if (!str_to_ulong(value, 10, &count)) { + LOG_ERR("%s:%d: expected an integer: %s", path, lineno, value); + return false; + } + conf->render_worker_count = count; + } + else { LOG_WARN("%s:%u: invalid key: %s", path, lineno, key); return false; @@ -427,6 +438,8 @@ config_load(struct config *conf) .cursor = 0, }, }, + + .render_worker_count = sysconf(_SC_NPROCESSORS_ONLN), }; char *path = get_config_path(); -- cgit v1.3