Rev 1892 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1892 | Rev 3959 | ||
---|---|---|---|
Line 146... | Line 146... | ||
146 | /* 1607 and 1451 are just a couple of arbitrary primes. */ |
146 | /* 1607 and 1451 are just a couple of arbitrary primes. */ |
147 | hash = _cairo_hash_string (family); |
147 | hash = _cairo_hash_string (family); |
148 | hash += ((unsigned long) slant) * 1607; |
148 | hash += ((unsigned long) slant) * 1607; |
149 | hash += ((unsigned long) weight) * 1451; |
149 | hash += ((unsigned long) weight) * 1451; |
Line 150... | Line -... | ||
150 | - | ||
151 | assert (hash != 0); |
150 | |
152 | key->base.hash_entry.hash = hash; |
151 | key->base.hash_entry.hash = hash; |
Line 153... | Line 152... | ||
153 | } |
152 | } |
154 | 153 | ||
Line 301... | Line 300... | ||
301 | /* Return existing font_face if it exists in the hash table. */ |
300 | /* Return existing font_face if it exists in the hash table. */ |
302 | font_face = _cairo_hash_table_lookup (hash_table, |
301 | font_face = _cairo_hash_table_lookup (hash_table, |
303 | &key.base.hash_entry); |
302 | &key.base.hash_entry); |
304 | if (font_face != NULL) { |
303 | if (font_face != NULL) { |
305 | if (font_face->base.status == CAIRO_STATUS_SUCCESS) { |
304 | if (font_face->base.status == CAIRO_STATUS_SUCCESS) { |
306 | /* We increment the reference count here manually to avoid |
- | |
307 | double-locking. */ |
- | |
308 | _cairo_reference_count_inc (&font_face->base.ref_count); |
305 | cairo_font_face_reference (&font_face->base); |
309 | _cairo_toy_font_face_hash_table_unlock (); |
306 | _cairo_toy_font_face_hash_table_unlock (); |
310 | return &font_face->base; |
307 | return &font_face->base; |
311 | } |
308 | } |
Line 312... | Line 309... | ||
312 | 309 | ||
313 | /* remove the bad font from the hash table */ |
310 | /* remove the bad font from the hash table */ |
314 | _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry); |
- | |
315 | font_face->base.hash_entry.hash = 0; |
311 | _cairo_hash_table_remove (hash_table, &font_face->base.hash_entry); |
Line 316... | Line 312... | ||
316 | } |
312 | } |
317 | 313 | ||
318 | /* Otherwise create it and insert into hash table. */ |
314 | /* Otherwise create it and insert into hash table. */ |
Line 350... | Line 346... | ||
350 | _cairo_toy_font_face_destroy (void *abstract_face) |
346 | _cairo_toy_font_face_destroy (void *abstract_face) |
351 | { |
347 | { |
352 | cairo_toy_font_face_t *font_face = abstract_face; |
348 | cairo_toy_font_face_t *font_face = abstract_face; |
353 | cairo_hash_table_t *hash_table; |
349 | cairo_hash_table_t *hash_table; |
Line 354... | Line -... | ||
354 | - | ||
355 | if (font_face == NULL || |
- | |
356 | CAIRO_REFERENCE_COUNT_IS_INVALID (&font_face->base.ref_count)) |
- | |
357 | return; |
- | |
358 | 350 | ||
359 | hash_table = _cairo_toy_font_face_hash_table_lock (); |
351 | hash_table = _cairo_toy_font_face_hash_table_lock (); |
360 | /* All created objects must have been mapped in the hash table. */ |
352 | /* All created objects must have been mapped in the hash table. */ |
Line 361... | Line 353... | ||
361 | assert (hash_table != NULL); |
353 | assert (hash_table != NULL); |
362 | 354 | ||
363 | if (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->base.ref_count)) { |
355 | if (CAIRO_REFERENCE_COUNT_HAS_REFERENCE (&font_face->base.ref_count)) { |
364 | /* somebody recreated the font whilst we waited for the lock */ |
356 | /* somebody recreated the font whilst we waited for the lock */ |
365 | _cairo_toy_font_face_hash_table_unlock (); |
357 | _cairo_toy_font_face_hash_table_unlock (); |
Line -... | Line 358... | ||
- | 358 | return; |
|
- | 359 | } |
|
- | 360 | ||
- | 361 | /* Font faces in SUCCESS status are guaranteed to be in the |
|
366 | return; |
362 | * hashtable. Font faces in an error status are removed from the |
- | 363 | * hashtable if they are found during a lookup, thus they should |
|
367 | } |
364 | * only be removed if they are in the hashtable. */ |
Line 368... | Line 365... | ||
368 | 365 | if (likely (font_face->base.status == CAIRO_STATUS_SUCCESS) || |
|
Line 369... | Line 366... | ||
369 | if (font_face->base.hash_entry.hash != 0) |
366 | _cairo_hash_table_lookup (hash_table, &font_face->base.hash_entry) == font_face) |