mirror of
https://github.com/gnustep/libs-performance.git
synced 2025-02-16 00:21:29 +00:00
thread exist safety fixup
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/performance/trunk@36058 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bd30ad1517
commit
dd0b17ac3c
2 changed files with 26 additions and 15 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2013-02-03 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* GSTicker.m: Retain timer so that we can safely invalidate it even
|
||||||
|
on thread exit when the runloop of the current thread may have been
|
||||||
|
deallocated already.
|
||||||
|
|
||||||
2012-01-11 Niels Grewe <niels.grewe@halbordnung.de>
|
2012-01-11 Niels Grewe <niels.grewe@halbordnung.de>
|
||||||
|
|
||||||
* GSSkipMutableArray.m: Change -initWithObjects:count: declaration
|
* GSSkipMutableArray.m: Change -initWithObjects:count: declaration
|
||||||
|
|
35
GSTicker.m
35
GSTicker.m
|
@ -66,6 +66,12 @@ static volatile NSTimeInterval lastTime = 0;
|
||||||
@interface GSTickerThread : NSObject
|
@interface GSTickerThread : NSObject
|
||||||
{
|
{
|
||||||
@public
|
@public
|
||||||
|
/* NB. We retain theTimer rather than depending on the run loop to do it.
|
||||||
|
* This is because tis object is typically deallocated on thread exist,
|
||||||
|
* so the thread's run loop may be deallocated before this object is
|
||||||
|
* deallocated, and we want to be sure the timer is not already deallocated
|
||||||
|
* when we invalidate it.
|
||||||
|
*/
|
||||||
NSTimer *theTimer;
|
NSTimer *theTimer;
|
||||||
NSMutableArray *observers;
|
NSMutableArray *observers;
|
||||||
unsigned last;
|
unsigned last;
|
||||||
|
@ -76,6 +82,7 @@ static volatile NSTimeInterval lastTime = 0;
|
||||||
- (void) dealloc
|
- (void) dealloc
|
||||||
{
|
{
|
||||||
[theTimer invalidate];
|
[theTimer invalidate];
|
||||||
|
[theTimer release];
|
||||||
theTimer = nil;
|
theTimer = nil;
|
||||||
[observers release];
|
[observers release];
|
||||||
observers = nil;
|
observers = nil;
|
||||||
|
@ -88,11 +95,11 @@ static volatile NSTimeInterval lastTime = 0;
|
||||||
NSTimeInterval ti = GSTickerTimeNow();
|
NSTimeInterval ti = GSTickerTimeNow();
|
||||||
|
|
||||||
observers = [NSMutableArray new];
|
observers = [NSMutableArray new];
|
||||||
theTimer = [NSTimer scheduledTimerWithTimeInterval: ti - (int)ti
|
theTimer = [[NSTimer scheduledTimerWithTimeInterval: ti - (int)ti
|
||||||
target: [GSTicker class]
|
target: [GSTicker class]
|
||||||
selector: @selector(_tick:)
|
selector: @selector(_tick:)
|
||||||
userInfo: self
|
userInfo: self
|
||||||
repeats: NO];
|
repeats: NO] retain];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -307,11 +314,9 @@ NSTimeInterval GSTickerTimeNow()
|
||||||
{
|
{
|
||||||
NSTimeInterval ti;
|
NSTimeInterval ti;
|
||||||
|
|
||||||
if (tt->theTimer != t)
|
[tt->theTimer invalidate];
|
||||||
{
|
[tt->theTimer release];
|
||||||
[tt->theTimer invalidate];
|
tt->theTimer = nil;
|
||||||
tt->theTimer = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ([tt->observers count] > 0)
|
if ([tt->observers count] > 0)
|
||||||
{
|
{
|
||||||
|
@ -339,11 +344,11 @@ NSTimeInterval GSTickerTimeNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
ti = GSTickerTimeNow();
|
ti = GSTickerTimeNow();
|
||||||
tt->theTimer = [NSTimer scheduledTimerWithTimeInterval: ti - (int)ti
|
tt->theTimer = [[NSTimer scheduledTimerWithTimeInterval: ti - (int)ti
|
||||||
target: self
|
target: self
|
||||||
selector: @selector(_tick:)
|
selector: @selector(_tick:)
|
||||||
userInfo: tt
|
userInfo: tt
|
||||||
repeats: NO];
|
repeats: NO] retain];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue