summaryrefslogtreecommitdiff
path: root/ext/gd/libgd
diff options
context:
space:
mode:
Diffstat (limited to 'ext/gd/libgd')
-rw-r--r--ext/gd/libgd/gd.h8
-rw-r--r--ext/gd/libgd/gdft.c18
2 files changed, 20 insertions, 6 deletions
diff --git a/ext/gd/libgd/gd.h b/ext/gd/libgd/gd.h
index 751a1e74e8..09accd78b3 100644
--- a/ext/gd/libgd/gd.h
+++ b/ext/gd/libgd/gd.h
@@ -301,6 +301,14 @@ void gdImageStringUp(gdImagePtr im, gdFontPtr f, int x, int y, unsigned char *s,
void gdImageString16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
void gdImageStringUp16(gdImagePtr im, gdFontPtr f, int x, int y, unsigned short *s, int color);
+/*
+ * The following functions are required to be called prior to the
+ * use of any sort of threads in a module load / shutdown function
+ * respectively.
+ */
+void gdFontCacheMutexSetup();
+void gdFontCacheMutexShutdown();
+
/* 2.0.16: for thread-safe use of gdImageStringFT and friends,
* call this before allowing any thread to call gdImageStringFT.
* Otherwise it is invoked by the first thread to invoke
diff --git a/ext/gd/libgd/gdft.c b/ext/gd/libgd/gdft.c
index 499de8637b..414f5e28eb 100644
--- a/ext/gd/libgd/gdft.c
+++ b/ext/gd/libgd/gdft.c
@@ -698,10 +698,8 @@ static char * gdft_draw_bitmap (gdCache_head_t *tc_cache, gdImage * im, int fg,
} else {
/* find antialised color */
tc_key.bgcolor = *pixel;
- gdMutexLock(gdFontCacheMutex);
tc_elem = (tweencolor_t *) gdCacheGet(tc_cache, &tc_key);
*pixel = tc_elem->tweencolor;
- gdMutexUnlock(gdFontCacheMutex);
}
}
}
@@ -722,7 +720,6 @@ void gdFontCacheShutdown()
gdCacheDelete(fontCache);
fontCache = NULL;
gdMutexUnlock(gdFontCacheMutex);
- gdMutexShutdown(gdFontCacheMutex);
FT_Done_FreeType(library);
}
}
@@ -732,15 +729,23 @@ void gdFreeFontCache()
gdFontCacheShutdown();
}
+void gdFontCacheMutexSetup()
+{
+ gdMutexSetup(gdFontCacheMutex);
+}
+
+void gdFontCacheMutexShutdown()
+{
+ gdMutexShutdown(gdFontCacheMutex);
+}
+
int gdFontCacheSetup(void)
{
if (fontCache) {
/* Already set up */
return 0;
}
- gdMutexSetup(gdFontCacheMutex);
if (FT_Init_FreeType(&library)) {
- gdMutexShutdown(gdFontCacheMutex);
return -1;
}
fontCache = gdCacheCreate (FONTCACHESIZE, fontTest, fontFetch, fontRelease);
@@ -803,15 +808,16 @@ gdImageStringFTEx (gdImage * im, int *brect, int fg, char *fontlist, double ptsi
/***** initialize font library and font cache on first call ******/
+ gdMutexLock(gdFontCacheMutex);
if (!fontCache) {
if (gdFontCacheSetup() != 0) {
gdCacheDelete(tc_cache);
+ gdMutexUnlock(gdFontCacheMutex);
return "Failure to initialize font library";
}
}
/*****/
- gdMutexLock(gdFontCacheMutex);
/* get the font (via font cache) */
fontkey.fontlist = fontlist;
fontkey.library = &library;