Author: rfm
Date: Tue May 19 16:03:31 2015
New Revision: 38511

URL: http://svn.gna.org/viewcvs/gnustep?rev=38511&view=rev
Log:
simplify GSIOThread exposure and locking

Modified:
    libs/performance/trunk/GSIOThreadPool.h
    libs/performance/trunk/GSIOThreadPool.m

Modified: libs/performance/trunk/GSIOThreadPool.h
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSIOThreadPool.h?rev=38511&r1=38510&r2=38511&view=diff
==============================================================================
--- libs/performance/trunk/GSIOThreadPool.h     (original)
+++ libs/performance/trunk/GSIOThreadPool.h     Tue May 19 16:03:31 2015
@@ -29,7 +29,6 @@
 typedef unsigned int NSUInteger;
 #endif
 
-@class NSLock;
 @class NSTimer;
 
 /** This is the class for threads in the pool.<br />
@@ -62,7 +61,6 @@
  */
 @interface     GSIOThreadPool : NSObject
 {
-  NSLock               *poolLock;
   NSMutableArray       *threads;
   NSTimeInterval       timeout;
   NSUInteger           maxThreads;

Modified: libs/performance/trunk/GSIOThreadPool.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/performance/trunk/GSIOThreadPool.m?rev=38511&r1=38510&r2=38511&view=diff
==============================================================================
--- libs/performance/trunk/GSIOThreadPool.m     (original)
+++ libs/performance/trunk/GSIOThreadPool.m     Tue May 19 16:03:31 2015
@@ -33,7 +33,7 @@
 
 /* Protect changes to a thread's counter
  */
-static NSLock   *countLock = nil;
+static NSRecursiveLock   *classLock = nil;
 
 @interface     GSIOThread (Private)
 - (NSUInteger) _count;
@@ -46,9 +46,9 @@
 
 + (void) initialize
 {
-  if (nil == countLock)
-    {
-      countLock = [NSLock new];
+  if (nil == classLock)
+    {
+      classLock = [NSRecursiveLock new];
     }
 }
 
@@ -116,14 +116,14 @@
     }
   [_timer invalidate];
 
-  [countLock lock];
+  [classLock lock];
   if (0 == _count || delay <= 0.0)
     {
       _count = NSNotFound;      // Mark as terminating
       _timer = nil;
       delay = 0.0;
     }
-  [countLock unlock];
+  [classLock unlock];
 
   if (delay > 0.0)
     {
@@ -182,6 +182,7 @@
     {
       NSInteger size;
 
+      [GSIOThread class];
       size = [[NSUserDefaults standardUserDefaults]
         integerForKey: @"GSIOThreadPoolSize"];
       if (size < 0)
@@ -203,13 +204,12 @@
   GSIOThread   *t;
   NSUInteger    c;
 
-  [poolLock lock];
+  [classLock lock];
   if (0 == maxThreads)
     {
-      [poolLock unlock];
+      [classLock unlock];
       return [NSThread mainThread];
     }
-  [countLock lock];
   t = best(threads);
   if (nil == t || ((c = [t _count]) > 0 && [threads count] < maxThreads))
     {
@@ -219,8 +219,7 @@
       c = 0;
     }
   [t _setCount: c + 1];
-  [countLock unlock];
-  [poolLock unlock];
+  [classLock unlock];
   return t;
 }
 
@@ -228,12 +227,12 @@
 {
   NSUInteger   count = 0;
 
-  [poolLock lock];
+  [classLock lock];
   if ([threads indexOfObjectIdenticalTo: aThread] != NSNotFound)
     {
       count = [((GSIOThread*)aThread) _count];
     }
-  [poolLock unlock];
+  [classLock unlock];
   return count;
 }
 
@@ -243,7 +242,7 @@
   GSIOThread   *thread;
   NSDate       *when = [NSDate dateWithTimeIntervalSinceNow: timeout];
 
-  [poolLock lock];
+  [classLock lock];
   while ((thread = [threads lastObject]) != nil)
     {
       [thread performSelector: @selector(terminate:)
@@ -253,8 +252,7 @@
       [threads removeLastObject];
     }
   [threads release];
-  [poolLock unlock];
-  [poolLock release];
+  [classLock unlock];
 #endif
   [super dealloc];
 }
@@ -264,7 +262,6 @@
 #if defined(GNUSTEP) || (MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_4)
   if ((self = [super init]) != nil)
     {
-      poolLock = [NSLock new];
       threads = [NSMutableArray new];
     }
 #else
@@ -282,9 +279,9 @@
 
 - (void) setThreads: (NSUInteger)max
 {
-  [poolLock lock];
+  [classLock lock];
   maxThreads = max;
-  [poolLock unlock];
+  [classLock unlock];
 }
 
 - (void) setTimeout: (NSTimeInterval)t
@@ -299,22 +296,19 @@
 
 - (void) unacquireThread: (NSThread*)aThread
 {
-  [poolLock lock];
+  [classLock lock];
   if ([threads indexOfObjectIdenticalTo: aThread] != NSNotFound)
     {
       NSUInteger        c;
 
-      [countLock lock];
       c = [((GSIOThread*)aThread) _count];
       if (0 == c)
        {
-          [countLock unlock];
-         [poolLock unlock];
+          [classLock unlock];
          [NSException raise: NSInternalInconsistencyException
                      format: @"-unacquireThread: called too many times"];
        }
       [((GSIOThread*)aThread) _setCount: --c];
-      [countLock unlock];
       if (0 == c && [threads count] > maxThreads)
         {
           [aThread retain];
@@ -326,7 +320,7 @@
           [aThread release];
         }
     }
-  [poolLock unlock];
+  [classLock unlock];
 }
 
 @end


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

Reply via email to