Author: spouliot
Date: 2006-05-31 10:45:07 -0400 (Wed, 31 May 2006)
New Revision: 61335

Modified:
   trunk/libgdiplus/src/ChangeLog
   trunk/libgdiplus/src/font.c
   trunk/libgdiplus/src/general.c
Log:
2006-05-31  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * font.c: Added mutexes for handling the generic (reference counted)
        fonts (serif, sans-serif, monospace) and when dealing the fontconfig's
        FcConfig (which isn't thread-safe and fails under heavy usage in 
        ASP.NET).
        * general.c: Added calls to fontconfig's FcInit and FcFini in 
        GdiplusStartup and GdiplusShutdown functions.



Modified: trunk/libgdiplus/src/ChangeLog
===================================================================
--- trunk/libgdiplus/src/ChangeLog      2006-05-31 14:34:27 UTC (rev 61334)
+++ trunk/libgdiplus/src/ChangeLog      2006-05-31 14:45:07 UTC (rev 61335)
@@ -1,3 +1,12 @@
+2006-05-31  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * font.c: Added mutexes for handling the generic (reference counted)
+       fonts (serif, sans-serif, monospace) and when dealing the fontconfig's
+       FcConfig (which isn't thread-safe and fails under heavy usage in 
+       ASP.NET).
+       * general.c: Added calls to fontconfig's FcInit and FcFini in 
+       GdiplusStartup and GdiplusShutdown functions.
+
 2006-05-30  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * font.c: Added more error checking when calling fontconfig API.

Modified: trunk/libgdiplus/src/font.c
===================================================================
--- trunk/libgdiplus/src/font.c 2006-05-31 14:34:27 UTC (rev 61334)
+++ trunk/libgdiplus/src/font.c 2006-05-31 14:45:07 UTC (rev 61335)
@@ -30,6 +30,7 @@
 
 
 /* Generic fonts families */
+static GStaticMutex generic = G_STATIC_MUTEX_INIT;
 static GpFontFamily* familySerif = NULL;
 static GpFontFamily* familySansSerif = NULL;
 static GpFontFamily* familyMonospace = NULL;
@@ -154,24 +155,34 @@
        
        if (!fontFamily)
                return Ok;
-               
+
+       g_static_mutex_lock (&generic);
+       
        if (fontFamily == familySerif) {
                ref_familySerif--;
                if (ref_familySerif)
                        delete = FALSE;
+               else
+                       familySerif = NULL;
        }
        
        if (fontFamily == familySansSerif) {
                ref_familySansSerif--;
                if (ref_familySansSerif)
                        delete = FALSE;
+               else
+                       familySansSerif = NULL;
        }       
        
        if (fontFamily == familyMonospace) {
                ref_familyMonospace--;
                if (ref_familyMonospace)
                        delete = FALSE;
+               else
+                       familyMonospace = NULL;
        }       
+
+       g_static_mutex_unlock (&generic);
        
        if (delete) {
                if (fontFamily->allocated) {
@@ -256,9 +267,11 @@
 static GpStatus
 create_fontfamily_from_name (unsigned char* name, GpFontFamily **fontFamily)
 {
+       static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
        GpStatus status;
        GpFontFamily *ff;
        FcValue val;
+       /* FcResult must be initialized because it's changed only in error 
conditions */
        FcResult rlt = FcResultMatch;
 
        FcPattern *pat = FcPatternCreate ();
@@ -273,8 +286,14 @@
                return GenericError;
        }
 
+       /* the default config (0 / NULL) cannot be used in multi-threaded code 
+        * (e.g. ASP.NET) without being protected.
+        */
+       g_static_mutex_lock (&mutex);
+
        if (!FcConfigSubstitute (0, pat, FcMatchPattern)) {
                FcPatternDestroy (pat);
+               g_static_mutex_unlock (&mutex);
                return GenericError;
        }
 
@@ -283,6 +302,7 @@
        gdip_createFontFamily (&ff);
        if (!ff) {
                FcPatternDestroy (pat);
+               g_static_mutex_unlock (&mutex);
                return OutOfMemory;
        }
 
@@ -302,6 +322,7 @@
                *fontFamily = NULL;
        }
 
+       g_static_mutex_unlock (&mutex);
        return status;
 }
 
@@ -377,39 +398,66 @@
 GdipGetGenericFontFamilySansSerif (GpFontFamily **nativeFamily)
 {
        const WCHAR MSSansSerif[] = {'M','S',' ','S','a','n','s',' ', 
'S','e','r','i','f', 0};
+       GpStatus status = Ok;
        
-       if (ref_familySansSerif == 0) 
-               GdipCreateFontFamilyFromName (MSSansSerif, NULL, 
&familySansSerif);    
-       
-       ref_familySansSerif++;
+       g_static_mutex_lock (&generic);
+
+       if (ref_familySansSerif == 0)
+               status = GdipCreateFontFamilyFromName (MSSansSerif, NULL, 
&familySansSerif);
+
+       if (status == Ok)
+               ref_familySansSerif++;
+       else
+               familySansSerif = NULL;
+
+       g_static_mutex_unlock (&generic);
+
        *nativeFamily = familySansSerif;    
-       return Ok;
+       return status;
 }
 
 GpStatus
 GdipGetGenericFontFamilySerif (GpFontFamily **nativeFamily)
 {
        const WCHAR Serif[] = {'S','e','r','i','f', 0};
+       GpStatus status = Ok;
        
+       g_static_mutex_lock (&generic);
+
        if (ref_familySerif == 0)
-               GdipCreateFontFamilyFromName (Serif, NULL, &familySerif);
-       
-       ref_familySerif++;      
-       *nativeFamily = familySerif;    
-       return Ok;
+               status = GdipCreateFontFamilyFromName (Serif, NULL, 
&familySerif);
+
+       if (status == Ok)
+               ref_familySerif++;
+       else
+               familySerif = NULL;
+
+       g_static_mutex_unlock (&generic);
+
+       *nativeFamily = familySerif;
+       return status;
 }
 
 GpStatus
 GdipGetGenericFontFamilyMonospace (GpFontFamily **nativeFamily)
 {
        const WCHAR Serif[] = {'S','e','r','i','f', 0};
+       GpStatus status = Ok;
        
+       g_static_mutex_lock (&generic);
+
        if (ref_familyMonospace == 0)
-               GdipCreateFontFamilyFromName (Serif, NULL, &familyMonospace);   
 
-               
-       ref_familyMonospace++;
+               status = GdipCreateFontFamilyFromName (Serif, NULL, 
&familyMonospace);
+
+       if (status == Ok)
+               ref_familyMonospace++;
+       else
+               familyMonospace = NULL;
+
+       g_static_mutex_unlock (&generic);
+
        *nativeFamily = familyMonospace;    
-       return Ok;
+       return status;
 }
 
 FT_Face

Modified: trunk/libgdiplus/src/general.c
===================================================================
--- trunk/libgdiplus/src/general.c      2006-05-31 14:34:27 UTC (rev 61334)
+++ trunk/libgdiplus/src/general.c      2006-05-31 14:45:07 UTC (rev 61335)
@@ -57,6 +57,7 @@
 {
        g_mem_allocations = NULL;
         initCodecList (); 
+       FcInit ();
        *token = 1;
        gdip_get_display_dpi();
 //     cairo_test_xlib_disable_render();
@@ -70,7 +71,7 @@
        GList* list = NULL;
 #endif
        releaseCodecList ();
-
+       FcFini ();
 #ifdef DEBUG_MEMLEAKS
        for (list = g_list_first (g_mem_allocations); list != NULL; list = 
g_list_next (list)) {
                printf ("Memory block not free'd at %x\n", list->data);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to