mirror of
https://github.com/gnustep/libs-performance.git
synced 2025-02-19 10:01:20 +00:00
Improve chances of threads being removed from pool when the limit is decreased.
This commit is contained in:
parent
7fa1246f24
commit
1a8c379be8
2 changed files with 17 additions and 2 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2023-02-03 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* GSIOThreadPool.m: If the maximum number of threads desired is
|
||||||
|
decreased so that we have more threads than we want, the excess
|
||||||
|
threads are now excluded from the set which may be acquired.
|
||||||
|
This should increase the chance of those threads being unacquired
|
||||||
|
so they can be terminated and removed from the pool.
|
||||||
|
|
||||||
2023-01-25 Wolfgang Lux <wolfgang.lux@gmail.com>
|
2023-01-25 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
* GSCache.m: Raise exception when attempting to insert object with
|
* GSCache.m: Raise exception when attempting to insert object with
|
||||||
|
|
|
@ -190,14 +190,21 @@ static NSRecursiveLock *classLock = nil;
|
||||||
static GSIOThreadPool *shared = nil;
|
static GSIOThreadPool *shared = nil;
|
||||||
|
|
||||||
/* Return the thread with the lowest usage.
|
/* Return the thread with the lowest usage.
|
||||||
|
* If there are more threads in the array than we want to use,
|
||||||
|
* those excess threads are excluded from the check so that
|
||||||
|
* their usage can drop to zero and they can be terminated.
|
||||||
*/
|
*/
|
||||||
static GSIOThread *
|
static GSIOThread *
|
||||||
best(NSMutableArray *a)
|
best(NSMutableArray *a, NSUInteger max)
|
||||||
{
|
{
|
||||||
NSUInteger c = [a count];
|
NSUInteger c = [a count];
|
||||||
NSUInteger l = NSNotFound;
|
NSUInteger l = NSNotFound;
|
||||||
GSIOThread *t = nil;
|
GSIOThread *t = nil;
|
||||||
|
|
||||||
|
if (c > max)
|
||||||
|
{
|
||||||
|
c = max;
|
||||||
|
}
|
||||||
while (c-- > 0)
|
while (c-- > 0)
|
||||||
{
|
{
|
||||||
GSIOThread *o = [a objectAtIndex: c];
|
GSIOThread *o = [a objectAtIndex: c];
|
||||||
|
@ -254,7 +261,7 @@ best(NSMutableArray *a)
|
||||||
}
|
}
|
||||||
|
|
||||||
[classLock lock];
|
[classLock lock];
|
||||||
t = best(threads);
|
t = best(threads, maxThreads);
|
||||||
if (nil == t || ((c = [t _count]) > 0 && [threads count] < maxThreads))
|
if (nil == t || ((c = [t _count]) > 0 && [threads count] < maxThreads))
|
||||||
{
|
{
|
||||||
NSString *n;
|
NSString *n;
|
||||||
|
|
Loading…
Reference in a new issue