From 6fa02dd96355ca945dea5232ecb37492425369dd Mon Sep 17 00:00:00 2001 From: rfm Date: Tue, 25 Jun 2013 09:22:49 +0000 Subject: [PATCH] Support shrinking number of threads in pool. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/performance/trunk@36753 72102866-910b-0410-8b05-ffd578937521 --- GSIOThreadPool.m | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/GSIOThreadPool.m b/GSIOThreadPool.m index 1fbfd8d..25a423f 100644 --- a/GSIOThreadPool.m +++ b/GSIOThreadPool.m @@ -221,13 +221,7 @@ best(NSMutableArray *a) - (void) setThreads: (NSUInteger)max { [poolLock lock]; - if (max != maxThreads) - { - maxThreads = max; - while ([threads count] > maxThreads) - { - } - } + maxThreads = max; [poolLock unlock]; } @@ -253,6 +247,17 @@ best(NSMutableArray *a) format: @"-unacquireThread: called too many times"]; } ((GSIOThread*)aThread)->count--; + if (0 == ((GSIOThread*)aThread)->count + && [threads count] > maxThreads) + { + [aThread retain]; + [threads removeObjectIdenticalTo: aThread]; + [aThread performSelector: @selector(terminate:) + onThread: aThread + withObject: [NSDate date] + waitUntilDone: NO]; + [aThread release]; + } } [poolLock unlock]; }