Improve perform in other threads

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27520 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2009-01-05 11:26:25 +00:00
parent aa26b4ea10
commit 49dfed3d80
5 changed files with 29 additions and 4 deletions

View file

@ -1,3 +1,12 @@
2009-01-05 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSRunLoop.m: check for performers in thread even if there are
no input sources available.
* Source/unix/GSRunLoopCtxt.m: Add diagnostics
* Source/win32/GSRunLoopCtxt.m: Add diagnostics
* Testing/thread.m: Change to allow perform in maion thrad to take
place and program to terminate.
2009-01-04 Richard Frith-Macdonald <rfm@gnu.org> 2009-01-04 Richard Frith-Macdonald <rfm@gnu.org>
* Source/mframe/sparc64/generic: guess at a config * Source/mframe/sparc64/generic: guess at a config

View file

@ -1129,9 +1129,18 @@ static inline BOOL timerInvalidated(NSTimer *t)
GSPrivateNotifyIdle(); GSPrivateNotifyIdle();
/* /*
* Pause for as long as possible (up to the limit date) * Pause for as long as possible (up to the limit date)
* Call the polling method so we notice thread notifications
* that methods should be performed in this loop.
*/ */
[NSThread sleepUntilDate: limit_date];
ti = [limit_date timeIntervalSinceNow]; ti = [limit_date timeIntervalSinceNow];
if (context == nil)
{
context = [[GSRunLoopCtxt alloc] initWithMode: mode
extra: _extra];
NSMapInsert(_contextMap, context->mode, context);
RELEASE(context);
}
[context pollUntil: (int)(ti * 1000) within: nil];
GSPrivateCheckTasks(); GSPrivateCheckTasks();
if (context != nil) if (context != nil)
{ {

View file

@ -571,6 +571,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
{ {
if (fd == threadInfo->inputFd) if (fd == threadInfo->inputFd)
{ {
NSDebugMLLog(@"NSRunLoop", @"Fire perform on thread");
[threadInfo fire]; [threadInfo fire];
watcher = nil; watcher = nil;
} }
@ -950,6 +951,7 @@ static void setPollfd(int fd, int event, GSRunLoopCtxt *ctxt)
if (fdIndex == threadInfo->inputFd) if (fdIndex == threadInfo->inputFd)
{ {
NSDebugMLLog(@"NSRunLoop", @"Fire perform on thread");
[threadInfo fire]; [threadInfo fire];
watcher = nil; watcher = nil;
} }

View file

@ -527,6 +527,7 @@ static const NSMapTableValueCallBacks WatcherMapValueCallBacks =
if (handle == threadInfo->event) if (handle == threadInfo->event)
{ {
watcher = nil; watcher = nil;
NSDebugMLLog(@"NSRunLoop", @"Fire perform on thread");
[threadInfo fire]; [threadInfo fire];
} }
else else

View file

@ -12,6 +12,7 @@
NSLock *lock = nil; NSLock *lock = nil;
unsigned retainReleaseThreads = 0; unsigned retainReleaseThreads = 0;
unsigned fireCount = 0;
@interface XX : NSObject @interface XX : NSObject
- (void) fire; - (void) fire;
@ -23,6 +24,7 @@ unsigned retainReleaseThreads = 0;
- (void) fire - (void) fire
{ {
NSLog(@"Got here"); NSLog(@"Got here");
fireCount++;
} }
- (void) retainRelease: (id)obj - (void) retainRelease: (id)obj
{ {
@ -34,10 +36,11 @@ unsigned retainReleaseThreads = 0;
[obj retain]; [obj retain];
[obj release]; [obj release];
} }
NSLog(@"Done %d retain/releases in thread %@", i, [NSThread currentThread]);
[lock lock]; [lock lock];
retainReleaseThreads++; retainReleaseThreads++;
[lock unlock]; [lock unlock];
NSLog(@"Done %d retain/releases in thread %@", i, [NSThread currentThread]); NSLog(@"Finished thread %@", [NSThread currentThread]);
} }
- (void) setup - (void) setup
{ {
@ -105,7 +108,7 @@ int main(int argc, char **argv, char **env)
[lock unlock]; // Allow other thread to proceed. [lock unlock]; // Allow other thread to proceed.
[[NSRunLoop currentRunLoop] runUntilDate: [[NSRunLoop currentRunLoop] runUntilDate:
[NSDate dateWithTimeIntervalSinceNow: 10.0]]; [NSDate dateWithTimeIntervalSinceNow: 30.0]];
NSLog(@"Done main thread"); NSLog(@"Done main thread");
@ -113,7 +116,8 @@ int main(int argc, char **argv, char **env)
{ {
NSLog(@"Waiting for all 5 retainRelease threads to complete (%d)", NSLog(@"Waiting for all 5 retainRelease threads to complete (%d)",
retainReleaseThreads); retainReleaseThreads);
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]]; [[NSRunLoop currentRunLoop] acceptInputForMode: NSDefaultRunLoopMode
beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
} }
if ([o retainCount] != 1) if ([o retainCount] != 1)
{ {