pajoye Wed Apr 4 00:47:55 2007 UTC Modified files: (Branch: PHP_5_2) /php-src/ext/gd config.m4 gd.c php_gd.h /php-src/ext/gd/libgd gd.h gdft.c Log: - MFH: - remove double lock (tween colors cache is created in each thread, the 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. http://cvs.php.net/viewvc.cgi/php-src/ext/gd/config.m4?r1=1.154.2.1.2.2&r2=1.154.2.1.2.3&diff_format=u Index: php-src/ext/gd/config.m4 diff -u php-src/ext/gd/config.m4:1.154.2.1.2.2 php-src/ext/gd/config.m4:1.154.2.1.2.3 --- php-src/ext/gd/config.m4:1.154.2.1.2.2 Sat Mar 10 12:18:36 2007 +++ php-src/ext/gd/config.m4 Wed Apr 4 00:47:55 2007 @@ -1,5 +1,5 @@ dnl -dnl $Id: config.m4,v 1.154.2.1.2.2 2007/03/10 12:18:36 pajoye Exp $ +dnl $Id: config.m4,v 1.154.2.1.2.3 2007/04/04 00:47:55 pajoye Exp $ dnl dnl @@ -284,6 +284,7 @@ PHP_CHECK_LIBRARY(gd, gdCacheCreate, [AC_DEFINE(HAVE_GD_CACHE_CREATE, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) PHP_CHECK_LIBRARY(gd, gdFontCacheShutdown, [AC_DEFINE(HAVE_GD_FONTCACHESHUTDOWN,1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) PHP_CHECK_LIBRARY(gd, gdFreeFontCache, [AC_DEFINE(HAVE_GD_FREEFONTCACHE, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) + PHP_CHECK_LIBRARY(gd, gdFontCacheMutexSetup, [AC_DEFINE(HAVE_GD_FONTMUTEX, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) PHP_CHECK_LIBRARY(gd, gdNewDynamicCtxEx, [AC_DEFINE(HAVE_GD_DYNAMIC_CTX_EX, 1, [ ])], [], [ -L$GD_LIB $GD_SHARED_LIBADD ]) ]) @@ -336,6 +337,7 @@ AC_DEFINE(HAVE_GD_GIF_CREATE, 1, [ ]) AC_DEFINE(HAVE_GD_IMAGEELLIPSE, 1, [ ]) AC_DEFINE(HAVE_GD_FONTCACHESHUTDOWN,1, [ ]) + AC_DEFINE(HAVE_GD_FONTMUTEX, 1, [ ]) AC_DEFINE(HAVE_GD_DYNAMIC_CTX_EX, 1, [ ]) AC_DEFINE(HAVE_GD_GIF_CTX, 1, [ ]) http://cvs.php.net/viewvc.cgi/php-src/ext/gd/gd.c?r1=1.312.2.20.2.15&r2=1.312.2.20.2.16&diff_format=u Index: php-src/ext/gd/gd.c diff -u php-src/ext/gd/gd.c:1.312.2.20.2.15 php-src/ext/gd/gd.c:1.312.2.20.2.16 --- php-src/ext/gd/gd.c:1.312.2.20.2.15 Sun Feb 11 11:11:48 2007 +++ php-src/ext/gd/gd.c Wed Apr 4 00:47:55 2007 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: gd.c,v 1.312.2.20.2.15 2007/02/11 11:11:48 pajoye Exp $ */ +/* $Id: gd.c,v 1.312.2.20.2.16 2007/04/04 00:47:55 pajoye Exp $ */ /* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, Cold Spring Harbor Labs. */ @@ -1147,11 +1147,7 @@ "gd", gd_functions, PHP_MINIT(gd), -#if HAVE_LIBT1 PHP_MSHUTDOWN(gd), -#else - NULL, -#endif NULL, #if HAVE_LIBGD20 && HAVE_GD_STRINGFT && (HAVE_GD_FONTCACHESHUTDOWN || HAVE_GD_FREEFONTCACHE) PHP_RSHUTDOWN(gd), @@ -1195,16 +1191,20 @@ } /* }}} */ -#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 @@ -1213,6 +1213,9 @@ { 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); http://cvs.php.net/viewvc.cgi/php-src/ext/gd/php_gd.h?r1=1.59.2.3.2.2&r2=1.59.2.3.2.3&diff_format=u Index: php-src/ext/gd/php_gd.h diff -u php-src/ext/gd/php_gd.h:1.59.2.3.2.2 php-src/ext/gd/php_gd.h:1.59.2.3.2.3 --- php-src/ext/gd/php_gd.h:1.59.2.3.2.2 Mon Jan 8 22:52:22 2007 +++ php-src/ext/gd/php_gd.h Wed Apr 4 00:47:55 2007 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_gd.h,v 1.59.2.3.2.2 2007/01/08 22:52:22 nlopess Exp $ */ +/* $Id: php_gd.h,v 1.59.2.3.2.3 2007/04/04 00:47:55 pajoye Exp $ */ #ifndef PHP_GD_H #define PHP_GD_H @@ -66,9 +66,7 @@ /* gd.c functions */ PHP_MINFO_FUNCTION(gd); PHP_MINIT_FUNCTION(gd); -#if HAVE_LIBT1 PHP_MSHUTDOWN_FUNCTION(gd); -#endif #if HAVE_LIBGD20 && HAVE_GD_STRINGFT PHP_RSHUTDOWN_FUNCTION(gd); #endif http://cvs.php.net/viewvc.cgi/php-src/ext/gd/libgd/gd.h?r1=1.26.2.3.2.2&r2=1.26.2.3.2.3&diff_format=u Index: php-src/ext/gd/libgd/gd.h diff -u php-src/ext/gd/libgd/gd.h:1.26.2.3.2.2 php-src/ext/gd/libgd/gd.h:1.26.2.3.2.3 --- php-src/ext/gd/libgd/gd.h:1.26.2.3.2.2 Sat Sep 16 19:07:45 2006 +++ php-src/ext/gd/libgd/gd.h Wed Apr 4 00:47:55 2007 @@ -301,6 +301,14 @@ 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 http://cvs.php.net/viewvc.cgi/php-src/ext/gd/libgd/gdft.c?r1=1.36.4.6&r2=1.36.4.7&diff_format=u Index: php-src/ext/gd/libgd/gdft.c diff -u php-src/ext/gd/libgd/gdft.c:1.36.4.6 php-src/ext/gd/libgd/gdft.c:1.36.4.7 --- php-src/ext/gd/libgd/gdft.c:1.36.4.6 Thu Mar 1 18:39:49 2007 +++ php-src/ext/gd/libgd/gdft.c Wed Apr 4 00:47:55 2007 @@ -698,10 +698,8 @@ } 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 @@ gdCacheDelete(fontCache); fontCache = NULL; gdMutexUnlock(gdFontCacheMutex); - gdMutexShutdown(gdFontCacheMutex); FT_Done_FreeType(library); } } @@ -732,15 +729,23 @@ 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 @@ /***** 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;
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php