[cairo] [PATCH V2 2/4] cairo_snapshot: Use rwlock to replace mutex.
Zhigang Gong
zhigang.gong at linux.intel.com
Mon May 28 06:09:23 PDT 2012
As we will use rwlock to fix the COW/replaying race condition,
we prefer to use one lock rather than two locks for one snapshot.
Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
---
src/cairo-surface-snapshot-inline.h | 4 ++--
src/cairo-surface-snapshot-private.h | 4 ++--
src/cairo-surface-snapshot.c | 8 ++++----
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/cairo-surface-snapshot-inline.h b/src/cairo-surface-snapshot-inline.h
index bf89c77..48b24a4 100644
--- a/src/cairo-surface-snapshot-inline.h
+++ b/src/cairo-surface-snapshot-inline.h
@@ -51,9 +51,9 @@ _cairo_surface_snapshot_get_target (cairo_surface_t *surface)
cairo_surface_snapshot_t *snapshot = (cairo_surface_snapshot_t *) surface;
cairo_surface_t *target;
- CAIRO_MUTEX_LOCK (snapshot->mutex);
+ CAIRO_RWLOCK_WRLOCK (snapshot->rwlock);
target = _cairo_surface_reference (snapshot->target);
- CAIRO_MUTEX_UNLOCK (snapshot->mutex);
+ CAIRO_RWLOCK_UNLOCK (snapshot->rwlock);
return target;
}
diff --git a/src/cairo-surface-snapshot-private.h b/src/cairo-surface-snapshot-private.h
index 58bee7b..43988bc 100644
--- a/src/cairo-surface-snapshot-private.h
+++ b/src/cairo-surface-snapshot-private.h
@@ -36,14 +36,14 @@
#ifndef CAIRO_SURFACE_SNAPSHOT_PRIVATE_H
#define CAIRO_SURFACE_SNAPSHOT_PRIVATE_H
-#include "cairo-mutex-private.h"
+#include "cairo-rwlock-private.h"
#include "cairo-surface-private.h"
#include "cairo-surface-backend-private.h"
struct _cairo_surface_snapshot {
cairo_surface_t base;
- cairo_mutex_t mutex;
+ cairo_rwlock_t rwlock;
cairo_surface_t *target;
cairo_surface_t *clone;
};
diff --git a/src/cairo-surface-snapshot.c b/src/cairo-surface-snapshot.c
index 9471e47..30e58fd 100644
--- a/src/cairo-surface-snapshot.c
+++ b/src/cairo-surface-snapshot.c
@@ -58,7 +58,7 @@ _cairo_surface_snapshot_finish (void *abstract_surface)
cairo_surface_destroy (surface->clone);
}
- CAIRO_MUTEX_FINI (surface->mutex);
+ CAIRO_RWLOCK_FINI (surface->rwlock);
return status;
}
@@ -184,7 +184,7 @@ _cairo_surface_snapshot_copy_on_write (cairo_surface_t *surface)
* been lost.
*/
- CAIRO_MUTEX_LOCK (snapshot->mutex);
+ CAIRO_RWLOCK_WRLOCK (snapshot->rwlock);
if (snapshot->target->backend->snapshot != NULL) {
clone = snapshot->target->backend->snapshot (snapshot->target);
@@ -212,7 +212,7 @@ done:
snapshot->target = snapshot->clone = clone;
snapshot->base.type = clone->type;
unlock:
- CAIRO_MUTEX_UNLOCK (snapshot->mutex);
+ CAIRO_RWLOCK_UNLOCK (snapshot->rwlock);
}
/**
@@ -269,7 +269,7 @@ _cairo_surface_snapshot (cairo_surface_t *surface)
surface->content);
snapshot->base.type = surface->type;
- CAIRO_MUTEX_INIT (snapshot->mutex);
+ CAIRO_RWLOCK_INIT (snapshot->rwlock);
snapshot->target = surface;
snapshot->clone = NULL;
--
1.7.4.4
More information about the cairo
mailing list