summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-07-30 15:43:03 +0200
committerAndrea Canciani <ranma42@gmail.com>2011-07-31 19:18:55 +0200
commitbb5512c4038cdd9aa4cec548a651d6cea9e14bdf (patch)
tree18b7327d47374acb999562971660c6a8b73fcc48
parente04e3687485a1988fd4084cca07ca4db4e2e7b96 (diff)
scaled-font: Update documentation and code with atomic refcountingwip/cleanup4
The documentation incorrectly states that cairo_scaled_font_reference() locks a mutex. This is not true anymore because refcounting is now done using atomics. For the same reason, it is now possible to reference the scaled font, instead of manually increasing its reference count, assuming that the reference function accepts inputs with no references.
-rw-r--r--src/cairo-scaled-font-private.h6
-rw-r--r--src/cairo-scaled-font.c25
2 files changed, 12 insertions, 19 deletions
diff --git a/src/cairo-scaled-font-private.h b/src/cairo-scaled-font-private.h
index 029377b17..5c0ba3c13 100644
--- a/src/cairo-scaled-font-private.h
+++ b/src/cairo-scaled-font-private.h
@@ -64,11 +64,7 @@ struct _cairo_scaled_font {
* the locks protecting them are as follows:
*
* 1. The reference count (scaled_font->ref_count)
- *
- * Modifications to the reference count are protected by the
- * _cairo_scaled_font_map_mutex. This is because the reference
- * count of a scaled font is intimately related with the font
- * map itself, (and the magic holdovers array).
+ * Modifications to the reference count are atomic.
*
* 2. The cache of glyphs (scaled_font->glyphs)
* 3. The backend private data (scaled_font->surface_backend,
diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index 6dc8ed39d..8d0699b5e 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -937,11 +937,9 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
assert (! scaled_font->placeholder);
if (likely (scaled_font->status == CAIRO_STATUS_SUCCESS)) {
- /* We increment the reference count manually here, (rather
- * than calling into cairo_scaled_font_reference), since we
- * must modify the reference count while our lock is still
- * held. */
- _cairo_reference_count_inc (&scaled_font->ref_count);
+ /* We must modify the reference count while our lock is
+ * still held. */
+ cairo_scaled_font_reference (scaled_font);
_cairo_scaled_font_map_unlock ();
return scaled_font;
}
@@ -1024,17 +1022,14 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
}
if (likely (scaled_font->status == CAIRO_STATUS_SUCCESS)) {
- /* We increment the reference count manually here, (rather
- * than calling into cairo_scaled_font_reference), since we
- * must modify the reference count while our lock is still
- * held. */
-
+ /* We must modify the reference count while our lock
+ * is still held. */
old = font_map->mru_scaled_font;
font_map->mru_scaled_font = scaled_font;
/* increment reference count for the mru cache */
- _cairo_reference_count_inc (&scaled_font->ref_count);
+ cairo_scaled_font_reference (scaled_font);
/* and increment for the returned reference */
- _cairo_reference_count_inc (&scaled_font->ref_count);
+ cairo_scaled_font_reference (scaled_font);
_cairo_scaled_font_map_unlock ();
cairo_scaled_font_destroy (old);
@@ -1092,7 +1087,7 @@ cairo_scaled_font_create (cairo_font_face_t *font_face,
if (likely (status == CAIRO_STATUS_SUCCESS)) {
old = font_map->mru_scaled_font;
font_map->mru_scaled_font = scaled_font;
- _cairo_reference_count_inc (&scaled_font->ref_count);
+ cairo_scaled_font_reference (scaled_font);
}
_cairo_scaled_font_map_unlock ();
@@ -1193,7 +1188,9 @@ cairo_scaled_font_reference (cairo_scaled_font_t *scaled_font)
CAIRO_REFERENCE_COUNT_IS_INVALID (&scaled_font->ref_count))
return scaled_font;
- assert (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&scaled_font->ref_count));
+ /* We would normally assert that we have a reference here but we
+ * can't get away with that because holdover scaled fonts have no
+ * references. */
_cairo_reference_count_inc (&scaled_font->ref_count);