Mercurial > sci
comparison sciworkerd/sciworkerd.c @ 75:72d998f01b4b
sciworkerd: cool down CPU usage
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 30 Jan 2023 08:42:40 +0100 |
parents | 95bc6b4ec753 |
children | 71cd8447e3a4 |
comparison
equal
deleted
inserted
replaced
74:38bdcfb3d4f7 | 75:72d998f01b4b |
---|---|
20 #include <poll.h> | 20 #include <poll.h> |
21 #include <signal.h> | 21 #include <signal.h> |
22 #include <stdint.h> | 22 #include <stdint.h> |
23 #include <string.h> | 23 #include <string.h> |
24 #include <time.h> | 24 #include <time.h> |
25 #include <unistd.h> | |
25 | 26 |
26 #include <utlist.h> | 27 #include <utlist.h> |
27 | 28 |
28 #include "apic.h" | 29 #include "apic.h" |
29 #include "log.h" | 30 #include "log.h" |
232 struct pollfd *fds; | 233 struct pollfd *fds; |
233 size_t fdsz, i = 0; | 234 size_t fdsz, i = 0; |
234 pid_t pid; | 235 pid_t pid; |
235 int ret; | 236 int ret; |
236 | 237 |
237 /* First, read every pipes. */ | 238 /* |
238 if (!(fdsz = count(tasks))) | 239 * Count every pipes. If there is no job we can just wait a little bit. |
240 */ | |
241 if (!(fdsz = count(tasks))) { | |
242 sleep(1); | |
239 return; | 243 return; |
244 } | |
240 | 245 |
241 fds = util_calloc(fdsz, sizeof (*fds)); | 246 fds = util_calloc(fdsz, sizeof (*fds)); |
242 | 247 |
243 for (iter = tasks; iter; iter = iter->next) | 248 for (iter = tasks; iter; iter = iter->next) |
244 task_prepare(iter->task, &fds[i++]); | 249 task_prepare(iter->task, &fds[i++]); |