mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 01:21:05 +00:00
Thread fixes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3131 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2fa149743a
commit
1244cd5310
3 changed files with 194 additions and 221 deletions
|
@ -1,3 +1,10 @@
|
|||
Tue Oct 27 15:20:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSDPSContext.m: Fixed per-thread code to be OpenStep
|
||||
complient and less inefficient.
|
||||
* Source/NSEvent.m: Fixed per-thread code to be OpenStep complient
|
||||
and less inefficient.
|
||||
|
||||
Mon Oct 26 13:20:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Tools/gpbs.m: Changed cStringNoCopy to cString.
|
||||
|
|
|
@ -60,20 +60,10 @@ NSString *DPSCantConnectException = @"DPSCantConnectException";
|
|||
//
|
||||
// Class variables
|
||||
//
|
||||
static NSMutableDictionary *GNU_CONTEXT_THREAD_DICT = nil;
|
||||
static NSRecursiveLock *GNU_CONTEXT_LOCK = nil;
|
||||
static NSString *GNU_CONTEXT_THREAD_KEY = @"GnuContextThreadKey";
|
||||
static BOOL GNU_CONTEXT_TRACED = NO;
|
||||
static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||
|
||||
#if defined(NeXT_PDO)
|
||||
@implementation NSThread (Containers)
|
||||
- copyWithZone:(NSZone*)zone
|
||||
{
|
||||
return [self retain];
|
||||
}
|
||||
@end
|
||||
#endif
|
||||
|
||||
@implementation NSDPSContext
|
||||
|
||||
+ (void)initialize
|
||||
|
@ -83,12 +73,6 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
|||
// Set initial version
|
||||
[self setVersion: 1];
|
||||
|
||||
// Allocate dictionary for maintaining
|
||||
// mapping of threads to contexts
|
||||
GNU_CONTEXT_THREAD_DICT = [NSMutableDictionary new];
|
||||
// Create lock for serializing access to dictionary
|
||||
GNU_CONTEXT_LOCK = [[NSRecursiveLock alloc] init];
|
||||
|
||||
GNU_CONTEXT_TRACED = NO;
|
||||
GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||
}
|
||||
|
@ -162,9 +146,8 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
|||
current_thread = [NSThread currentThread];
|
||||
|
||||
// Get current context for current thread
|
||||
[GNU_CONTEXT_LOCK lock];
|
||||
|
||||
current_context = [GNU_CONTEXT_THREAD_DICT objectForKey: current_thread];
|
||||
current_context = [[current_thread threadDictionary] objectForKey: GNU_CONTEXT_THREAD_KEY];
|
||||
|
||||
// If not in dictionary then create one
|
||||
if (!current_context)
|
||||
|
@ -172,7 +155,6 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
|||
current_context = [[NSDPSContext alloc] init];
|
||||
[self setCurrentContext: current_context];
|
||||
}
|
||||
[GNU_CONTEXT_LOCK unlock];
|
||||
|
||||
return current_context;
|
||||
}
|
||||
|
@ -181,20 +163,15 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
|||
{
|
||||
NSThread *current_thread = [NSThread currentThread];
|
||||
|
||||
[GNU_CONTEXT_LOCK lock];
|
||||
|
||||
// If no context then remove from dictionary
|
||||
if (!context)
|
||||
{
|
||||
[GNU_CONTEXT_THREAD_DICT removeObjectForKey: current_thread];
|
||||
[[current_thread threadDictionary] removeObjectForKey: GNU_CONTEXT_THREAD_KEY];
|
||||
}
|
||||
else
|
||||
{
|
||||
[GNU_CONTEXT_THREAD_DICT setObject: context
|
||||
forKey: current_thread];
|
||||
[[current_thread threadDictionary] setObject: context forKey: GNU_CONTEXT_THREAD_KEY];
|
||||
}
|
||||
|
||||
[GNU_CONTEXT_LOCK unlock];
|
||||
}
|
||||
|
||||
- (NSDPSContext *)DPSContext
|
||||
|
|
|
@ -46,8 +46,7 @@
|
|||
@implementation NSEvent
|
||||
|
||||
// Class variables
|
||||
static NSMutableDictionary* timers = nil;
|
||||
static NSRecursiveLock* timersLock = nil;
|
||||
static NSString *timerKey = @"NSEventTimersKey";
|
||||
|
||||
//
|
||||
// Class methods
|
||||
|
@ -60,8 +59,6 @@ static NSRecursiveLock* timersLock = nil;
|
|||
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
timers = [NSMutableDictionary new];
|
||||
timersLock = [NSRecursiveLock new];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,17 +191,15 @@ NSEvent *e = [[[NSEvent alloc] init] autorelease];
|
|||
+ (void)startPeriodicEventsAfterDelay:(NSTimeInterval)delaySeconds
|
||||
withPeriod:(NSTimeInterval)periodSeconds
|
||||
{
|
||||
NSTimer* timer;
|
||||
NSThread* currentThread = [NSThread currentThread];
|
||||
|
||||
[timersLock lock];
|
||||
NSTimer* timer;
|
||||
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||
|
||||
NSDebugLog (@"startPeriodicEventsAfterDelay:withPeriod:");
|
||||
// Check this thread
|
||||
if ([timers objectForKey:currentThread]) // for a pending timer
|
||||
if ([dict objectForKey: timerKey]) // for a pending timer
|
||||
[NSException raise:NSInternalInconsistencyException
|
||||
format:@"Periodic events are already being generated for "
|
||||
@"this thread %x", currentThread];
|
||||
@"this thread %x", [NSThread currentThread]];
|
||||
// If the delay time is 0 then register
|
||||
// a timer immediately. Otherwise
|
||||
// register a timer with no repeat that
|
||||
|
@ -221,11 +216,9 @@ NSThread* currentThread = [NSThread currentThread];
|
|||
userInfo:[NSNumber numberWithDouble:periodSeconds]
|
||||
repeats:NO];
|
||||
|
||||
[[NSRunLoop currentRunLoop] addTimer:timer
|
||||
forMode:NSEventTrackingRunLoopMode];
|
||||
[timers setObject:timer forKey:currentThread];
|
||||
|
||||
[timersLock unlock];
|
||||
[[NSRunLoop currentRunLoop] addTimer: timer
|
||||
forMode: NSEventTrackingRunLoopMode];
|
||||
[dict setObject: timer forKey: timerKey];
|
||||
}
|
||||
|
||||
+ (void)_timerFired:(NSTimer*)timer
|
||||
|
@ -248,9 +241,10 @@ NSEvent* periodicEvent = [self otherEventWithType:NSPeriodic
|
|||
|
||||
+ (void)_registerRealTimer:(NSTimer*)timer
|
||||
{ // this method provides a
|
||||
NSTimer* realTimer; // means of delaying the
|
||||
NSTimer* realTimer; // means of delaying the
|
||||
// start of periodic events
|
||||
[timersLock lock];
|
||||
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||
|
||||
NSDebugLog (@"_registerRealTimer:");
|
||||
|
||||
realTimer = [NSTimer timerWithTimeInterval:[[timer userInfo] doubleValue]
|
||||
|
@ -259,28 +253,23 @@ NSTimer* realTimer; // means of delaying the
|
|||
userInfo:nil
|
||||
repeats:YES]; // Add the real timer to the timers
|
||||
// dictionary and to the run loop
|
||||
[timers setObject:realTimer forKey:[NSThread currentThread]];
|
||||
[[NSRunLoop currentRunLoop] addTimer:realTimer
|
||||
forMode:NSEventTrackingRunLoopMode];
|
||||
|
||||
[timersLock unlock];
|
||||
/* xxx what if there is already a timer - are we sure there isn't? */
|
||||
[dict setObject: realTimer forKey: timerKey];
|
||||
[[NSRunLoop currentRunLoop] addTimer: realTimer
|
||||
forMode: NSEventTrackingRunLoopMode];
|
||||
}
|
||||
|
||||
+ (void)stopPeriodicEvents
|
||||
{
|
||||
NSTimer* timer;
|
||||
NSThread* currentThread;
|
||||
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||
|
||||
NSDebugLog (@"stopPeriodicEvents");
|
||||
[timersLock lock];
|
||||
|
||||
currentThread = [NSThread currentThread];
|
||||
/* Remove any existing timer for this thread */
|
||||
timer = [timers objectForKey:currentThread];
|
||||
timer = [dict objectForKey: timerKey];
|
||||
[timer invalidate];
|
||||
[timers removeObjectForKey:currentThread];
|
||||
|
||||
[timersLock unlock];
|
||||
[dict removeObjectForKey: timerKey];
|
||||
}
|
||||
|
||||
//
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue