]> granicus.if.org Git - php/commitdiff
- remove double lock (tween colors cache is created in each thread, the
authorPierre Joye <pajoye@php.net>
Wed, 4 Apr 2007 00:44:38 +0000 (00:44 +0000)
committerPierre Joye <pajoye@php.net>
Wed, 4 Apr 2007 00:44:38 +0000 (00:44 +0000)
  cache mutex is already locked earlier)
- #40858, other TS improvements for gd freetype cache management
  cache initialization and shutdown is now done in MINIT and MSHUTDOWN.

ext/gd/gd.c
ext/gd/libgd/gd.h
ext/gd/libgd/gdft.c

index 2a0d99704c905f53d9f1357e833d09d69914f323..f8b39fb25f2216d4a1d026b4adfd17e04986bf54 100644 (file)
@@ -1078,11 +1078,7 @@ zend_module_entry gd_module_entry = {
        "gd",
        gd_functions,
        PHP_MINIT(gd),
-#if HAVE_LIBT1
        PHP_MSHUTDOWN(gd),
-#else
-       NULL,
-#endif
        NULL,
 #if HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE)
        PHP_RSHUTDOWN(gd),
@@ -1126,16 +1122,20 @@ static void php_free_gd_font(zend_rsrc_list_entry *rsrc TSRMLS_DC)
 }
 /* }}} */
 
-#if HAVE_LIBT1
+
 /* {{{ PHP_MSHUTDOWN_FUNCTION
  */
 PHP_MSHUTDOWN_FUNCTION(gd)
 {
+#if HAVE_LIBT1
        T1_CloseLib();
+#endif
+#if HAVE_GD_FONTMUTEX
+       gdFontCacheMutexShutdown();
+#endif
        return SUCCESS;
 }
 /* }}} */
-#endif
 
 
 /* {{{ PHP_MINIT_FUNCTION
@@ -1144,6 +1144,9 @@ PHP_MINIT_FUNCTION(gd)
 {
        le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
        le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
+#if HAVE_GD_FONTMUTEX
+       gdFontCacheMutexSetup();
+#endif
 #if HAVE_LIBT1
        T1_SetBitmapPad(8);
        T1_InitLib(NO_LOGFILE | IGNORE_CONFIGFILE | IGNORE_FONTDATABASE);
index be353abb53a4b568856029ed87c831a561f58a7b..226edd16a782454dc5b4df2de47ffa6da595160d 100644 (file)
@@ -297,6 +297,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
index 499de8637b2d51036efaa1f073c6ce05312178d9..414f5e28ebbace5d469e1b952bb73fd5295dbe0d 100644 (file)
@@ -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;