Author: paullanders
Date: Mon Mar 23 23:05:57 2015
New Revision: 38430

URL: http://svn.gna.org/viewcvs/gnustep?rev=38430&view=rev
Log:
Expansion to Marcian's temporary patch to account for more levels of recursion.


Modified:
    libs/gui/branches/gnustep_testplant_branch/Source/NSStringDrawing.m

Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSStringDrawing.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSStringDrawing.m?rev=38430&r1=38429&r2=38430&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSStringDrawing.m 
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSStringDrawing.m Mon Mar 
23 23:05:57 2015
@@ -143,6 +143,40 @@
     }
 }
 
+static int lockedCacheEntries[NUM_CACHE_ENTRIES];
+static unsigned int numLockedCacheEntries = 0;
+#define DEBUG_CACHE_RECURSION_COUNT 0
+
+static inline BOOL is_entry_locked(unsigned int entry)
+{
+  int i;
+  for (i=0; i<numLockedCacheEntries; i++)
+    {
+      if (lockedCacheEntries[i]==entry) return YES;
+    }
+  return NO;
+}
+
+static inline void lock_entry(unsigned int entry)
+{
+  lockedCacheEntries[numLockedCacheEntries++] = entry;
+
+#if DEBUG_CACHE_RECURSION_COUNT
+  static BOOL printing = YES;
+  if (printing || numLockedCacheEntries > 1)
+    {
+      printf("Locked Entries: %d\n", numLockedCacheEntries);
+         printing = numLockedCacheEntries > 1;
+    }
+#endif
+}
+
+static inline void unlock_top_entry()
+{
+  if ( numLockedCacheEntries )
+      numLockedCacheEntries--;
+}
+
 static inline void cache_lock()
 {
   // FIXME: Put all the init code into an +initialize method
@@ -160,6 +194,7 @@
 
 static inline void cache_unlock()
 {
+  unlock_top_entry();
   [cacheLock unlock];
 }
 
@@ -181,8 +216,6 @@
 
 static int cache_match(int hasSize, NSSize size, int useScreenFonts, int 
*matched)
 {
-  static int LastReplaced = 0;
-  
   int i, j;
   cache_t *c;
   int least_used;
@@ -213,7 +246,7 @@
       if (least_used == -1 || c->used < least_used)
         {
           // Avoid replacing the very last one in case of recursion...
-          if (j != LastReplaced)
+          if (!is_entry_locked(j))
             {
               least_used = c->used;
               replace = j;
@@ -247,6 +280,7 @@
 #ifdef STATS
           hits++;
 #endif
+
           return j;
         }
     }
@@ -257,7 +291,6 @@
   misses++;
 #endif
   *matched     = 0;
-  LastReplaced = replace;
   
   c = cache + replace;
   c->used = 1;
@@ -307,6 +340,7 @@
   NSTextContainer *textContainer;
 
   ci = cache_match(hasSize, size, useScreenFonts, &hit);
+  lock_entry(ci);
   if (hit)
     {
       return ci;


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to