[gegl] buffer: fix small bug in async file backend
- From: Ville Sokk <villesokk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] buffer: fix small bug in async file backend
- Date: Mon, 13 Aug 2012 19:23:44 +0000 (UTC)
commit ee6fd99fe7f2b70183ca9b6ff9db434d92c4b74b
Author: Ville Sokk <ville sokk gmail com>
Date: Mon Aug 13 22:15:17 2012 +0300
buffer: fix small bug in async file backend
gegl/buffer/gegl-tile-backend-file-async.c | 24 ++++++++++++++----------
gegl/buffer/gegl-tile-backend-file.h | 1 +
2 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/gegl/buffer/gegl-tile-backend-file-async.c b/gegl/buffer/gegl-tile-backend-file-async.c
index b0f9b1b..b27f2be 100644
--- a/gegl/buffer/gegl-tile-backend-file-async.c
+++ b/gegl/buffer/gegl-tile-backend-file-async.c
@@ -24,7 +24,10 @@
* the main gegl thread and the writer thread is performed using a
* queue. The writer thread sleeps if the queue is empty. If an entry is
* read and the tile is in the queue then its data is copied from the
- * queue instead of read from disk.
+ * queue instead of read from disk. There are two locks, queue_mutex and
+ * write_mutex. The first one is used to append to the queue or read from
+ * it, the second one to completely stop the writer thread from working
+ * (to remove/change queue entries).
*/
#include "config.h"
@@ -352,13 +355,11 @@ gegl_tile_backend_file_entry_write (GeglTileBackendFile *self,
guchar *source)
{
GeglFileBackendThreadParams *params;
- gint length = gegl_tile_backend_get_tile_size (GEGL_TILE_BACKEND (self));
- guchar *new_source = g_malloc (length);
+ gint length = gegl_tile_backend_get_tile_size (GEGL_TILE_BACKEND (self));
+ guchar *new_source;
gegl_tile_backend_file_ensure_exist (self);
- memcpy (new_source, source, length);
-
if (entry->link)
{
g_mutex_lock (write_mutex);
@@ -366,9 +367,7 @@ gegl_tile_backend_file_entry_write (GeglTileBackendFile *self,
if (entry->link)
{
params = (GeglFileBackendThreadParams *)entry->link->data;
-
- g_free (params->source);
- params->source = new_source;
+ memcpy (params->source, source, length);
g_mutex_unlock (write_mutex);
return;
}
@@ -376,6 +375,9 @@ gegl_tile_backend_file_entry_write (GeglTileBackendFile *self,
g_mutex_unlock (write_mutex);
}
+ new_source = g_malloc (length);
+ memcpy (new_source, source, length);
+
params = g_new0 (GeglFileBackendThreadParams, 1);
params->operation = OP_WRITE;
params->length = length;
@@ -473,9 +475,11 @@ gegl_tile_backend_file_file_entry_destroy (GeglFileBackendEntry *entry,
if (entry->link)
{
- g_free (((GeglFileBackendThreadParams *)entry->link->data)->source);
- g_free (entry->link->data);
+ GeglFileBackendThreadParams *queued_op = entry->link->data;
+ queued_op->file->pending_ops -= 1;
g_queue_delete_link (&queue, entry->link);
+ g_free (queued_op->source);
+ g_free (queued_op);
}
g_mutex_unlock (write_mutex);
diff --git a/gegl/buffer/gegl-tile-backend-file.h b/gegl/buffer/gegl-tile-backend-file.h
index d9348c6..b9366e9 100644
--- a/gegl/buffer/gegl-tile-backend-file.h
+++ b/gegl/buffer/gegl-tile-backend-file.h
@@ -49,6 +49,7 @@ typedef enum
typedef struct
{
GeglBufferTile *tile;
+ /* reference to the writer queue link of this entry */
GList *link;
} GeglFileBackendEntry;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]