mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Complete update of NSThread for MacOS-X 10.5 compatibility. Needs testing.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26332 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
766e0dbf1a
commit
7c710cfbcb
9 changed files with 454 additions and 300 deletions
|
@ -43,6 +43,7 @@
|
|||
#include "Foundation/NSStream.h"
|
||||
#include "Foundation/NSThread.h"
|
||||
#include "Foundation/NSDebug.h"
|
||||
#include "Foundation/NSInvocation.h"
|
||||
#include "GSRunLoopCtxt.h"
|
||||
#include "GSRunLoopWatcher.h"
|
||||
#include "GSStream.h"
|
||||
|
@ -667,9 +668,61 @@ static inline BOOL timerInvalidated(NSTimer *t)
|
|||
*/
|
||||
+ (NSRunLoop*) currentRunLoop
|
||||
{
|
||||
extern NSRunLoop *GSRunLoopForThread();
|
||||
GSRunLoopThreadInfo *info = GSRunLoopInfoForThread(nil);
|
||||
NSRunLoop *current = info->loop;
|
||||
|
||||
return GSRunLoopForThread(nil);
|
||||
if (current == nil)
|
||||
{
|
||||
current = info->loop = [self new];
|
||||
/* If this is the main thread, set up a housekeeping timer.
|
||||
*/
|
||||
if ([GSCurrentThread() isMainThread] == YES)
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL (arp);
|
||||
GSRunLoopCtxt *context;
|
||||
NSNotificationCenter *ctr;
|
||||
NSNotification *not;
|
||||
NSInvocation *inv;
|
||||
NSTimer *timer;
|
||||
SEL sel;
|
||||
|
||||
ctr = [NSNotificationCenter defaultCenter];
|
||||
not = [NSNotification notificationWithName: @"GSHousekeeping"
|
||||
object: nil
|
||||
userInfo: nil];
|
||||
sel = @selector(postNotification:);
|
||||
inv = [NSInvocation invocationWithMethodSignature:
|
||||
[ctr methodSignatureForSelector: sel]];
|
||||
[inv setTarget: ctr];
|
||||
[inv setSelector: sel];
|
||||
[inv setArgument: ¬ atIndex: 2];
|
||||
[inv retainArguments];
|
||||
|
||||
context = NSMapGet(current->_contextMap, NSDefaultRunLoopMode);
|
||||
if (context == nil)
|
||||
{
|
||||
context = [GSRunLoopCtxt alloc];
|
||||
context = [context initWithMode: NSDefaultRunLoopMode
|
||||
extra: current->_extra];
|
||||
NSMapInsert(current->_contextMap, context->mode, context);
|
||||
RELEASE(context);
|
||||
}
|
||||
if (context->housekeeper != timer)
|
||||
{
|
||||
[context->housekeeper invalidate];
|
||||
DESTROY(context->housekeeper);
|
||||
}
|
||||
timer = [[NSTimer alloc] initWithFireDate: nil
|
||||
interval: 30.0
|
||||
target: inv
|
||||
selector: NULL
|
||||
userInfo: nil
|
||||
repeats: YES];
|
||||
context->housekeeper = timer;
|
||||
RELEASE(arp);
|
||||
}
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
/* This is the designated initializer. */
|
||||
|
@ -1404,28 +1457,3 @@ static inline BOOL timerInvalidated(NSTimer *t)
|
|||
|
||||
@end
|
||||
|
||||
@implementation NSRunLoop (Housekeeper)
|
||||
- (void) _setHousekeeper: (NSTimer*)timer
|
||||
{
|
||||
GSRunLoopCtxt *context;
|
||||
|
||||
context = NSMapGet(_contextMap, NSDefaultRunLoopMode);
|
||||
if (context == nil)
|
||||
{
|
||||
context = [[GSRunLoopCtxt alloc] initWithMode: NSDefaultRunLoopMode
|
||||
extra: _extra];
|
||||
NSMapInsert(_contextMap, context->mode, context);
|
||||
RELEASE(context);
|
||||
}
|
||||
if (context->housekeeper != timer)
|
||||
{
|
||||
[context->housekeeper invalidate];
|
||||
DESTROY(context->housekeeper);
|
||||
}
|
||||
if (timer != nil)
|
||||
{
|
||||
context->housekeeper = RETAIN(timer);
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue