Author: rfm
Date: Fri Jun 20 17:39:25 2014
New Revision: 37957

URL: http://svn.gna.org/viewcvs/gnustep?rev=37957&view=rev
Log:
Remove proxy for improved performance and (hopefully) simplification of code.

Modified:
    libs/sqlclient/trunk/SQLClient.h
    libs/sqlclient/trunk/SQLClient.m
    libs/sqlclient/trunk/testPostgres.m

Modified: libs/sqlclient/trunk/SQLClient.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.h?rev=37957&r1=37956&r2=37957&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.h    (original)
+++ libs/sqlclient/trunk/SQLClient.h    Fri Jun 20 17:39:25 2014
@@ -340,6 +340,8 @@
  * of any earlier call to the function.
  */
 extern unsigned        SQLClientTimeTick();
+
+@class SQLClientPool;
 
 /**
  * <p>The SQLClient class encapsulates dynamic SQL access to relational
@@ -398,6 +400,7 @@
   unsigned int         _connectFails;  /** The count of connection failures */
   NSMapTable            *_observers;    /** Observations of async events */
   NSCountedSet          *_names;        /** Track notification names */
+  SQLClientPool         *_pool;         /** The pool of the client (or nil) */
   /** Allow for extensions by allocating memory and pointing to it from
    * the _extra ivar.  That way we can avoid binary incompatibility between
    * minor releases.
@@ -639,7 +642,7 @@
  * a nil name is supplied, defaults to the value of SQLClientName in the
  * configuration dictionary (or in the standard user defaults).  If there is
  * no value for SQLClientName, uses the string 'Database'.<br />
- * If forUseInPool is NO and a SQLClient instance already exists with the
+ * If pool is nil and a SQLClient instance already exists with the
  * name used for this instance, the receiver is deallocated and the existing
  * instance is retained and returned ... there may only ever be one instance
  * for a particular reference name which is not in a pool.<br />
@@ -663,7 +666,7 @@
  */
 - (id) initWithConfiguration: (NSDictionary*)config
                        name: (NSString*)reference
-                        pool: (BOOL)forUseInPool;
+                        pool: (SQLClientPool*)pool;
 
 /** Two clients are considered equal if they refer to the same database
  * and are logged in as the same database user using the same protocol.
@@ -1395,7 +1398,7 @@
 /** <p>An SQLClientPool instance may be used to create/control a pool of
  * client objects.  Code may obtain autoreleased proxies to the clients
  * from the pool and use them safe in the knowledge that they won't be
- * used anywhere else ... as soon as the proxy is deallocated the client
+ * used anywhere else ... as soon as the client would be deallocated, it
  * is returned to the pool.
  * </p>
  * <p>All clients in the pool share the same cache object, so query results
@@ -1406,7 +1409,7 @@
 {
   NSConditionLock       *lock;  /** Controls access to the pool contents */
   SQLClient             **c;    /** The clients of the pool. */
-  SQLClient             **p;    /** The proxies of the pool. */
+  BOOL                  *u;     /** Whether the client is in use. */
   int                   max;    /** Maximum connection count */
   int                   min;    /** Minimum connection count */
   NSTimeInterval       _duration;      /** Duration logging threshold */
@@ -1429,13 +1432,13 @@
                          max: (int)maxConnections
                          min: (int)minConnections;
 
-/** Fetches an (autoreleased) proxy to a client from the pool.<br />
+/** Fetches an (autoreleased) client from the pool.<br />
  * This method blocks indefinitely waiting for a client to become
  * available in the pool.
  */
 - (SQLClient*) provideClient;
 
-/** Fetches an (autoreleased) proxy to a client from the pool.<br />
+/** Fetches an (autoreleased) client from the pool.<br />
  * If no client is or becomes available before the specified date then
  * the method returns nil.<br />
  * If when is nil then a date in the distant future is used so that
@@ -1461,16 +1464,15 @@
  */
 - (void) setDurationLogging: (NSTimeInterval)threshold;
 
-/** Takes the client form the provided proxy and places it back
- * in the queue (so the proxy stops using it).  This happens automatically
- * when the proxy is deallocated so you don't generally needs to do it.<br />
- * Returns YES if the supplied proxy referred to a client in the pool,
- * NO otherwise.<br />
+/** Puts the client back in the pool.  This happens automatically
+ * when a client from a pool would normally be deallocated so you don't
+ * generally need to do it.<br />
+ * Returns YES if the supplied client was from the pool, NO otherwise.<br />
  * If the swallowed client would take the count of idle client connections
  * in the pool above the configured minimum, the oldest (ie longest idle)
  * client in the pool is disconnected.
  */
-- (BOOL) swallowClient: (SQLClient*)proxy;
+- (BOOL) swallowClient: (SQLClient*)client;
 
 @end
 

Modified: libs/sqlclient/trunk/SQLClient.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/SQLClient.m?rev=37957&r1=37956&r2=37957&view=diff
==============================================================================
--- libs/sqlclient/trunk/SQLClient.m    (original)
+++ libs/sqlclient/trunk/SQLClient.m    Fri Jun 20 17:39:25 2014
@@ -1020,7 +1020,7 @@
 
   [clientsLock lock];
   NSHashRemove(clientsHash, (void*)self);
-  if (_name != nil && NO == _forUseInPool)
+  if (_name != nil && nil == _pool)
     {
       NSMapRemove(clientsMap, (void*)_name);
     }
@@ -1168,13 +1168,13 @@
 - (id) initWithConfiguration: (NSDictionary*)config
                        name: (NSString*)reference
 {
-  return [self initWithConfiguration: config name: reference pool: NO];
+  return [self initWithConfiguration: config name: reference pool: nil];
 }
 
 
 - (id) initWithConfiguration: (NSDictionary*)config
                        name: (NSString*)reference
-                        pool: (BOOL)forUseInPool
+                        pool: (SQLClientPool*)pool
 {
   NSNotification       *n;
   NSDictionary         *conf = config;
@@ -1196,14 +1196,14 @@
     }
 
   [clientsLock lock];
-  _forUseInPool = (NO == forUseInPool) ? NO : YES;
-  if (YES == _forUseInPool)
+  _pool = pool;
+  if (nil == _pool)
+    {
+      existing = nil;
+    }
+  else
     {
       existing = (SQLClient*)NSMapGet(clientsMap, reference);
-    }
-  else
-    {
-      existing = nil;
     }
   if (nil == existing)
     {
@@ -1584,7 +1584,14 @@
   [clientsLock lock];
   if (NSDecrementExtraRefCountWasZero(self))
     {
-      [self dealloc];
+      if (nil != _pool)
+        {
+          [_pool swallowClient: self];
+        }
+      else
+        {
+          [self dealloc];
+        }
     }
   [clientsLock unlock];
 }
@@ -1652,7 +1659,7 @@
       if ([s isEqual: _name] == NO)
         {
           [clientsLock lock];
-          if (NO == _forUseInPool)
+          if (nil == _pool)
             {
               if (NSMapGet(clientsMap, s) != 0)
                 {
@@ -1670,7 +1677,7 @@
             {
               [self disconnect];
             }
-          if (NO == _forUseInPool && _name != nil)
+          if (nil == _pool && _name != nil)
             {
               NSMapRemove(clientsMap, (void*)_name);
             }
@@ -1679,7 +1686,7 @@
           _name = s;
           [_client release];
           _client = [[[NSProcessInfo processInfo] globallyUniqueString] 
retain];
-          if (NO == _forUseInPool && _name != nil)
+          if (nil == _pool && _name != nil)
             {
               NSMapInsert(clientsMap, (void*)_name, (void*)self);
             }

Modified: libs/sqlclient/trunk/testPostgres.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/sqlclient/trunk/testPostgres.m?rev=37957&r1=37956&r2=37957&view=diff
==============================================================================
--- libs/sqlclient/trunk/testPostgres.m (original)
+++ libs/sqlclient/trunk/testPostgres.m Fri Jun 20 17:39:25 2014
@@ -73,6 +73,19 @@
                                                 name: @"test"
                                                  max: 2
                                                  min: 1] autorelease];
+#if 0
+{
+  NSAutoreleasePool     *p = [NSAutoreleasePool new];
+  SQLClient             *c0;
+  SQLClient             *c1;
+
+  [sp setDebugging: 2];
+  c0 = [sp provideClient];
+  c1 = [sp provideClient];
+  [sp provideClientBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 25.0]];
+  [p release];
+}
+#endif
   db = [sp provideClient];
   [sp swallowClient: db];
   db = [sp provideClient];


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

Reply via email to