mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-15 20:18:05 +02:00
gtask: fix task_wait_time estimation
The wait time is estimated as function of the number of running threads Fixes #1683
This commit is contained in:
parent
01cff0e9b8
commit
b465cb158b
10
gio/gtask.c
10
gio/gtask.c
@ -619,11 +619,14 @@ static gint tasks_running;
|
|||||||
* The base and multiplier below gives us 10 extra threads after about
|
* The base and multiplier below gives us 10 extra threads after about
|
||||||
* a second of blocking, 30 after 5 seconds, 100 after a minute, and
|
* a second of blocking, 30 after 5 seconds, 100 after a minute, and
|
||||||
* 200 after 20 minutes.
|
* 200 after 20 minutes.
|
||||||
|
*
|
||||||
|
* We specify maximum pool size of 330 to increase the waiting time up
|
||||||
|
* to around 30 minutes.
|
||||||
*/
|
*/
|
||||||
#define G_TASK_POOL_SIZE 10
|
#define G_TASK_POOL_SIZE 10
|
||||||
#define G_TASK_WAIT_TIME_BASE 100000
|
#define G_TASK_WAIT_TIME_BASE 100000
|
||||||
#define G_TASK_WAIT_TIME_MULTIPLIER 1.03
|
#define G_TASK_WAIT_TIME_MULTIPLIER 1.03
|
||||||
#define G_TASK_WAIT_TIME_MAX (30 * 60 * 1000000)
|
#define G_TASK_WAIT_TIME_MAX_POOL_SIZE 330
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_task_init (GTask *task)
|
g_task_init (GTask *task)
|
||||||
@ -1359,7 +1362,7 @@ g_task_thread_setup (void)
|
|||||||
|
|
||||||
if (tasks_running == G_TASK_POOL_SIZE)
|
if (tasks_running == G_TASK_POOL_SIZE)
|
||||||
task_wait_time = G_TASK_WAIT_TIME_BASE;
|
task_wait_time = G_TASK_WAIT_TIME_BASE;
|
||||||
else if (tasks_running > G_TASK_POOL_SIZE && task_wait_time < G_TASK_WAIT_TIME_MAX)
|
else if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE)
|
||||||
task_wait_time *= G_TASK_WAIT_TIME_MULTIPLIER;
|
task_wait_time *= G_TASK_WAIT_TIME_MULTIPLIER;
|
||||||
|
|
||||||
if (tasks_running >= G_TASK_POOL_SIZE)
|
if (tasks_running >= G_TASK_POOL_SIZE)
|
||||||
@ -1381,6 +1384,9 @@ g_task_thread_cleanup (void)
|
|||||||
else if (tasks_running + tasks_pending < G_TASK_POOL_SIZE)
|
else if (tasks_running + tasks_pending < G_TASK_POOL_SIZE)
|
||||||
g_source_set_ready_time (task_pool_manager, -1);
|
g_source_set_ready_time (task_pool_manager, -1);
|
||||||
|
|
||||||
|
if (tasks_running > G_TASK_POOL_SIZE && tasks_running < G_TASK_WAIT_TIME_MAX_POOL_SIZE)
|
||||||
|
task_wait_time /= G_TASK_WAIT_TIME_MULTIPLIER;
|
||||||
|
|
||||||
tasks_running--;
|
tasks_running--;
|
||||||
g_mutex_unlock (&task_pool_mutex);
|
g_mutex_unlock (&task_pool_mutex);
|
||||||
g_private_set (&task_private, GUINT_TO_POINTER (FALSE));
|
g_private_set (&task_private, GUINT_TO_POINTER (FALSE));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user