Skip to content

Commit

Permalink
Changes to locking with USE_THREAD
Browse files Browse the repository at this point in the history
  • Loading branch information
a-samuelssson authored and rouault committed Oct 4, 2020
1 parent b07d5df commit 2039bca
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions fontcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,21 @@ unsigned int msGetGlyphIndex(face_element *face, unsigned int unicode) {
if(face->face->charmap && face->face->charmap->encoding == FT_ENCODING_MS_SYMBOL) {
unicode |= 0xf000; /* why? */
}
#ifdef USE_THREAD
if (use_global_ft_cache)
msAcquireLock(TLOCK_TTF);
#endif
UT_HASH_FIND_INT(face->index_cache,&unicode,ic);
if(!ic) {
ic = msSmallMalloc(sizeof(index_element));
ic->codepoint = FT_Get_Char_Index(face->face,unicode);
ic->unicode = unicode;
UT_HASH_ADD_INT(face->index_cache,unicode,ic);
}
#ifdef USE_THREAD
if (use_global_ft_cache)
msReleaseLock(TLOCK_TTF);
#endif
return ic->codepoint;
}

Expand Down Expand Up @@ -267,6 +275,10 @@ glyph_element* msGetGlyphByIndex(face_element *face, unsigned int size, unsigned
memset(&key,0,sizeof(glyph_element_key));
key.codepoint = codepoint;
key.size = size;
#ifdef USE_THREAD
if (use_global_ft_cache)
msAcquireLock(TLOCK_TTF);
#endif
UT_HASH_FIND(hh,face->glyph_cache,&key,sizeof(glyph_element_key),gc);
if(!gc) {
FT_Error error;
Expand All @@ -278,6 +290,10 @@ glyph_element* msGetGlyphByIndex(face_element *face, unsigned int size, unsigned
if(error) {
msSetError(MS_MISCERR, "unable to load glyph %ud for font \"%s\"", "msGetGlyphByIndex()",key.codepoint, face->font);
free(gc);
#ifdef USE_THREAD
if (use_global_ft_cache)
msReleaseLock(TLOCK_TTF);
#endif
return NULL;
}
gc->metrics.minx = face->face->glyph->metrics.horiBearingX / 64.0;
Expand All @@ -288,6 +304,10 @@ glyph_element* msGetGlyphByIndex(face_element *face, unsigned int size, unsigned
gc->key = key;
UT_HASH_ADD(hh,face->glyph_cache,key,sizeof(glyph_element_key), gc);
}
#ifdef USE_THREAD
if (use_global_ft_cache)
msReleaseLock(TLOCK_TTF);
#endif
return gc;
}

Expand Down

0 comments on commit 2039bca

Please sign in to comment.