summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Canciani <ranma42@gmail.com>2011-07-30 15:43:03 +0200
committerAndrea Canciani <ranma42@gmail.com>2011-08-14 16:02:13 +0200
commit15596fc27547f0a434e2c48027e43758ac35618e (patch)
tree42047d4e9fd73e415efc47b17647167648280be6
parentc353dfca539e84c68e55ddca15d1e80553a4623e (diff)
scaled-font: Update documentation and code with atomic refcounting
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 cb59bce67..3eb84eb7d 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -925,11 +925,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;
}
@@ -1012,17 +1010,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);
@@ -1080,7 +1075,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 ();
@@ -1181,7 +1176,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);