Author: rfm
Date: Mon May  4 14:15:47 2015
New Revision: 38473

URL: http://svn.gna.org/viewcvs/gnustep?rev=38473&view=rev
Log:
Tweak to allow connections in a pool to share a cache effectively

Modified:
    libs/sqlclient/trunk/SQLClient.m

Modified: libs/sqlclient/trunk/SQLClient.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.m?rev=38473&r1=38472&r2=38473&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.m    (original)
+++ libs/sqlclient/trunk/SQLClient.m    Mon May  4 14:15:47 2015
@@ -722,6 +722,7 @@
 /**
  * Container for all instances.
  */
+static NSRecursiveLock *cacheLock = nil;
 static NSHashTable     *clientsHash = 0;
 static NSMapTable      *clientsMap = 0;
 static NSRecursiveLock *clientsLock = nil;
@@ -866,9 +867,10 @@
       modes[0] = NSDefaultRunLoopMode;
       queryModes = [[NSArray alloc] initWithObjects: modes count: 1];
       GSTickerTimeNow();
-      [SQLRecord class];       // Force initialisation
+      [SQLRecord class];       // Force initialisatio
       if (0 == clientsHash)
         {
+          cacheLock = [NSRecursiveLock new];
           clientsHash = NSCreateHashTable(NSNonOwnedPointerHashCallBacks, 0);
           clientsMap = NSCreateMapTable(NSObjectMapKeyCallBacks,
             NSNonRetainedObjectMapValueCallBacks, 0);
@@ -2821,7 +2823,11 @@
 {
   GSCache      *c;
 
-  [lock lock];
+  /* NB we use a different lock to protect the cache from the lock
+   * used to protect the database query.  That allows multiple
+   * connections (a connection pool) to share the same cache.
+   */
+  [cacheLock lock];
   if (nil == _cache)
     {
       _cache = [GSCache new];
@@ -2831,7 +2837,7 @@
        }
     }
   c = [_cache retain];
-  [lock unlock];
+  [cacheLock unlock];
   return [c autorelease];
 }
 
@@ -2969,7 +2975,11 @@
 
 - (void) setCache: (GSCache*)aCache
 {
-  [lock lock];
+  /* NB we use a different lock to protect the cache from the lock
+   * used to protect the database query.  That allows multiple
+   * connections (a connection pool) to share the same cache.
+   */
+  [cacheLock lock];
   NS_DURING
     {
       if (_cacheThread != nil)
@@ -2986,11 +2996,11 @@
     }
   NS_HANDLER
     {
-      [lock unlock];
+      [cacheLock unlock];
       [localException raise];
     }
   NS_ENDHANDLER
-  [lock unlock];
+  [cacheLock unlock];
 }
 
 - (void) setCacheThread: (NSThread*)aThread


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

Reply via email to