[gegl/soc-2013-n-point-deformation] buffer: use MB to limit size of file backend's writer thread queue instead of number of queue entrie
- From: Marek Dvoroznak <dvoromar src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/soc-2013-n-point-deformation] buffer: use MB to limit size of file backend's writer thread queue instead of number of queue entrie
- Date: Wed, 3 Jul 2013 17:23:05 +0000 (UTC)
commit 60c2b52e86603bdd20a11c3acb020aa643129210
Author: Ville Sokk <ville sokk gmail com>
Date: Thu Jun 27 12:18:51 2013 +0300
buffer: use MB to limit size of file backend's writer thread queue instead of number of queue entries
gegl/buffer/gegl-tile-backend-file-async.c | 27 ++++++++++++++---------
gegl/gegl-config.c | 20 ++++++++--------
gegl/gegl-config.h | 2 +-
gegl/gegl-init.c | 32 ++++++++++++++--------------
4 files changed, 43 insertions(+), 38 deletions(-)
---
diff --git a/gegl/buffer/gegl-tile-backend-file-async.c b/gegl/buffer/gegl-tile-backend-file-async.c
index 14beb3a..577021d 100644
--- a/gegl/buffer/gegl-tile-backend-file-async.c
+++ b/gegl/buffer/gegl-tile-backend-file-async.c
@@ -158,6 +158,7 @@ static GQueue queue = G_QUEUE_INIT;
static GMutex mutex = { 0, };
static GCond queue_cond = { 0, };
static GCond max_cond = { 0, };
+static gint queue_size = 0;
static GeglFileBackendThreadParams *in_progress;
@@ -173,14 +174,10 @@ gegl_tile_backend_file_finish_writing (GeglTileBackendFile *self)
static void
gegl_tile_backend_file_push_queue (GeglFileBackendThreadParams *params)
{
- guint length;
-
g_mutex_lock (&mutex);
- length = g_queue_get_length (&queue);
-
/* block if the queue has gotten too big */
- if (length > gegl_config ()->queue_limit)
+ while (queue_size > gegl_config ()->queue_size)
g_cond_wait (&max_cond, &mutex);
params->file->pending_ops += 1;
@@ -189,7 +186,11 @@ gegl_tile_backend_file_push_queue (GeglFileBackendThreadParams *params)
if (params->entry)
{
if (params->operation == OP_WRITE)
- params->entry->tile_link = g_queue_peek_tail_link (&queue);
+ {
+ params->entry->tile_link = g_queue_peek_tail_link (&queue);
+ queue_size += params->length + sizeof (GList) +
+ sizeof (GeglFileBackendThreadParams);
+ }
else /* OP_WRITE_BLOCK */
params->entry->block_link = g_queue_peek_tail_link (&queue);
}
@@ -285,12 +286,16 @@ gegl_tile_backend_file_writer_thread (gpointer ignored)
if (params->file->pending_ops == 0)
g_cond_signal (¶ms->file->cond);
- /* unblock the main thread if the queue had gotten too big */
- if (g_queue_get_length (&queue) < gegl_config ()->queue_limit)
- g_cond_signal (&max_cond);
+ if (params->operation == OP_WRITE)
+ {
+ queue_size -= params->length + sizeof (GList) +
+ sizeof (GeglFileBackendThreadParams);
+ g_free (params->source);
- if (params->source)
- g_free (params->source);
+ /* unblock the main thread if the queue had gotten too big */
+ if (queue_size < gegl_config ()->queue_size)
+ g_cond_signal (&max_cond);
+ }
g_free (params);
diff --git a/gegl/gegl-config.c b/gegl/gegl-config.c
index 60b66b2..bb813fc 100644
--- a/gegl/gegl-config.c
+++ b/gegl/gegl-config.c
@@ -45,7 +45,7 @@ enum
PROP_TILE_HEIGHT,
PROP_THREADS,
PROP_USE_OPENCL,
- PROP_QUEUE_LIMIT
+ PROP_QUEUE_SIZE
};
static void
@@ -94,8 +94,8 @@ gegl_config_get_property (GObject *gobject,
g_value_set_boolean (value, config->use_opencl);
break;
- case PROP_QUEUE_LIMIT:
- g_value_set_int (value, config->queue_limit);
+ case PROP_QUEUE_SIZE:
+ g_value_set_int (value, config->queue_size);
break;
default:
@@ -169,8 +169,8 @@ gegl_config_set_property (GObject *gobject,
case PROP_USE_OPENCL:
config->use_opencl = g_value_get_boolean (value);
break;
- case PROP_QUEUE_LIMIT:
- config->queue_limit = g_value_get_int (value);
+ case PROP_QUEUE_SIZE:
+ config->queue_size = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, property_id, pspec);
@@ -273,11 +273,11 @@ gegl_config_class_init (GeglConfigClass *klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
- g_object_class_install_property (gobject_class, PROP_QUEUE_LIMIT,
- g_param_spec_int ("queue-limit",
- "Queue limit",
- "Maximum number of entries in the file tile backend's
writer queue",
- 2, G_MAXINT, 1000,
+ g_object_class_install_property (gobject_class, PROP_QUEUE_SIZE,
+ g_param_spec_int ("queue-size",
+ "Queue size",
+ "Maximum size of a file backend's writer thread queue
(in bytes)",
+ 2, G_MAXINT, 50 * 1024 *1024,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
}
diff --git a/gegl/gegl-config.h b/gegl/gegl-config.h
index 4d4c3b4..c45c0c9 100644
--- a/gegl/gegl-config.h
+++ b/gegl/gegl-config.h
@@ -44,7 +44,7 @@ struct _GeglConfig
gint tile_height;
gint threads;
gboolean use_opencl;
- gint queue_limit;
+ gint queue_size;
};
struct _GeglConfigClass
diff --git a/gegl/gegl-init.c b/gegl/gegl-init.c
index 921cf26..fb07890 100644
--- a/gegl/gegl-init.c
+++ b/gegl/gegl-init.c
@@ -227,15 +227,15 @@ gegl_init (gint *argc,
g_option_context_free (context);
}
-static gchar *cmd_gegl_swap = NULL;
-static gchar *cmd_gegl_cache_size = NULL;
-static gchar *cmd_gegl_chunk_size = NULL;
-static gchar *cmd_gegl_quality = NULL;
-static gchar *cmd_gegl_tile_size = NULL;
-static gchar *cmd_babl_tolerance = NULL;
-static gchar *cmd_gegl_threads = NULL;
-static gboolean *cmd_gegl_opencl = NULL;
-static gint *cmd_gegl_queue_limit = NULL;
+static gchar *cmd_gegl_swap = NULL;
+static gchar *cmd_gegl_cache_size = NULL;
+static gchar *cmd_gegl_chunk_size = NULL;
+static gchar *cmd_gegl_quality = NULL;
+static gchar *cmd_gegl_tile_size = NULL;
+static gchar *cmd_babl_tolerance = NULL;
+static gchar *cmd_gegl_threads = NULL;
+static gboolean *cmd_gegl_opencl = NULL;
+static gchar *cmd_gegl_queue_size = NULL;
static const GOptionEntry cmd_entries[]=
{
@@ -280,9 +280,9 @@ static const GOptionEntry cmd_entries[]=
N_("Use OpenCL"), NULL
},
{
- "gegl-queue-limit", 0, 0,
- G_OPTION_ARG_INT, &cmd_gegl_queue_limit,
- N_("Maximum number of entries in the file tile backend's writer queue"), "<count>"
+ "gegl-queue-size", 0, 0,
+ G_OPTION_ARG_STRING, &cmd_gegl_queue_size,
+ N_("Maximum size of a file backend's writer thread queue (in MB)"), "<count>"
},
{ NULL }
};
@@ -336,8 +336,8 @@ GeglConfig *gegl_config (void)
else
config->use_opencl = TRUE;
- if (g_getenv ("GEGL_QUEUE_LIMIT"))
- config->queue_limit = atoi(g_getenv ("GEGL_QUEUE_LIMIT"));
+ if (g_getenv ("GEGL_QUEUE_SIZE"))
+ config->queue_size = atoi(g_getenv ("GEGL_QUEUE_SIZE")) * 1024 * 1024;
if (gegl_swap_dir())
config->swap = g_strdup(gegl_swap_dir ());
@@ -553,8 +553,8 @@ gegl_post_parse_hook (GOptionContext *context,
/* don't override the environment variable */
if (g_getenv ("GEGL_USE_OPENCL") == NULL && cmd_gegl_opencl)
g_object_set (config, "use-opencl", cmd_gegl_opencl, NULL);
- if (cmd_gegl_queue_limit)
- g_object_set (config, "queue-limit", cmd_gegl_queue_limit, NULL);
+ if (cmd_gegl_queue_size)
+ config->queue_size = atoi (cmd_gegl_queue_size) * 1024 * 1024;
GEGL_INSTRUMENT_START();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]