From 5f883b7ad1182fce6eef3a71dc62b9cb9c1123c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Sun, 9 Oct 2016 14:33:19 -0300 Subject: [PATCH] (task_http) Don't use 100% CPU in threaded mode This task is network bound and the HTTP functions use non-blocking I/O, so task_http_iterate_transfer() returns "too fast" and the worker thread gets no rest. --- libretro-common/queues/task_queue.c | 4 ---- tasks/task_http.c | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libretro-common/queues/task_queue.c b/libretro-common/queues/task_queue.c index f83d98d66a..0787f14c54 100644 --- a/libretro-common/queues/task_queue.c +++ b/libretro-common/queues/task_queue.c @@ -454,10 +454,6 @@ static void threaded_worker(void *userdata) task_queue_put(&tasks_finished, task); slock_unlock(finished_lock); } - -#if 0 - retro_sleep(10); -#endif } } diff --git a/tasks/task_http.c b/tasks/task_http.c index 4276b3e454..c22fde832b 100644 --- a/tasks/task_http.c +++ b/tasks/task_http.c @@ -119,6 +119,10 @@ static int task_http_iterate_transfer(retro_task_t *task) http_handle_t *http = (http_handle_t*)task->state; size_t pos = 0, tot = 0; + /* FIXME: This wouldn't be needed if we could wait for a timeout */ + if (task_queue_ctl(TASK_QUEUE_CTL_IS_THREADED, NULL)) + retro_sleep(1); + if (!net_http_update(http->handle, &pos, &tot)) { task->progress = (tot == 0) ? -1 : (signed)(pos * 100 / tot);