mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-02 12:20:59 +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>
|
Mon Oct 26 13:20:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||||
|
|
||||||
* Tools/gpbs.m: Changed cStringNoCopy to cString.
|
* Tools/gpbs.m: Changed cStringNoCopy to cString.
|
||||||
|
|
|
@ -60,20 +60,10 @@ NSString *DPSCantConnectException = @"DPSCantConnectException";
|
||||||
//
|
//
|
||||||
// Class variables
|
// Class variables
|
||||||
//
|
//
|
||||||
static NSMutableDictionary *GNU_CONTEXT_THREAD_DICT = nil;
|
static NSString *GNU_CONTEXT_THREAD_KEY = @"GnuContextThreadKey";
|
||||||
static NSRecursiveLock *GNU_CONTEXT_LOCK = nil;
|
|
||||||
static BOOL GNU_CONTEXT_TRACED = NO;
|
static BOOL GNU_CONTEXT_TRACED = NO;
|
||||||
static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||||
|
|
||||||
#if defined(NeXT_PDO)
|
|
||||||
@implementation NSThread (Containers)
|
|
||||||
- copyWithZone:(NSZone*)zone
|
|
||||||
{
|
|
||||||
return [self retain];
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@implementation NSDPSContext
|
@implementation NSDPSContext
|
||||||
|
|
||||||
+ (void)initialize
|
+ (void)initialize
|
||||||
|
@ -83,12 +73,6 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||||
// Set initial version
|
// Set initial version
|
||||||
[self setVersion: 1];
|
[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_TRACED = NO;
|
||||||
GNU_CONTEXT_SYNCHRONIZED = NO;
|
GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||||
}
|
}
|
||||||
|
@ -162,9 +146,8 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||||
current_thread = [NSThread currentThread];
|
current_thread = [NSThread currentThread];
|
||||||
|
|
||||||
// Get current context for current thread
|
// 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 not in dictionary then create one
|
||||||
if (!current_context)
|
if (!current_context)
|
||||||
|
@ -172,7 +155,6 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||||
current_context = [[NSDPSContext alloc] init];
|
current_context = [[NSDPSContext alloc] init];
|
||||||
[self setCurrentContext: current_context];
|
[self setCurrentContext: current_context];
|
||||||
}
|
}
|
||||||
[GNU_CONTEXT_LOCK unlock];
|
|
||||||
|
|
||||||
return current_context;
|
return current_context;
|
||||||
}
|
}
|
||||||
|
@ -181,20 +163,15 @@ static BOOL GNU_CONTEXT_SYNCHRONIZED = NO;
|
||||||
{
|
{
|
||||||
NSThread *current_thread = [NSThread currentThread];
|
NSThread *current_thread = [NSThread currentThread];
|
||||||
|
|
||||||
[GNU_CONTEXT_LOCK lock];
|
|
||||||
|
|
||||||
// If no context then remove from dictionary
|
// If no context then remove from dictionary
|
||||||
if (!context)
|
if (!context)
|
||||||
{
|
{
|
||||||
[GNU_CONTEXT_THREAD_DICT removeObjectForKey: current_thread];
|
[[current_thread threadDictionary] removeObjectForKey: GNU_CONTEXT_THREAD_KEY];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[GNU_CONTEXT_THREAD_DICT setObject: context
|
[[current_thread threadDictionary] setObject: context forKey: GNU_CONTEXT_THREAD_KEY];
|
||||||
forKey: current_thread];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[GNU_CONTEXT_LOCK unlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDPSContext *)DPSContext
|
- (NSDPSContext *)DPSContext
|
||||||
|
|
|
@ -46,8 +46,7 @@
|
||||||
@implementation NSEvent
|
@implementation NSEvent
|
||||||
|
|
||||||
// Class variables
|
// Class variables
|
||||||
static NSMutableDictionary* timers = nil;
|
static NSString *timerKey = @"NSEventTimersKey";
|
||||||
static NSRecursiveLock* timersLock = nil;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Class methods
|
// Class methods
|
||||||
|
@ -60,8 +59,6 @@ static NSRecursiveLock* timersLock = nil;
|
||||||
|
|
||||||
// Initial version
|
// Initial version
|
||||||
[self setVersion:1];
|
[self setVersion:1];
|
||||||
timers = [NSMutableDictionary new];
|
|
||||||
timersLock = [NSRecursiveLock new];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,16 +192,14 @@ NSEvent *e = [[[NSEvent alloc] init] autorelease];
|
||||||
withPeriod:(NSTimeInterval)periodSeconds
|
withPeriod:(NSTimeInterval)periodSeconds
|
||||||
{
|
{
|
||||||
NSTimer* timer;
|
NSTimer* timer;
|
||||||
NSThread* currentThread = [NSThread currentThread];
|
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||||
|
|
||||||
[timersLock lock];
|
|
||||||
|
|
||||||
NSDebugLog (@"startPeriodicEventsAfterDelay:withPeriod:");
|
NSDebugLog (@"startPeriodicEventsAfterDelay:withPeriod:");
|
||||||
// Check this thread
|
// Check this thread
|
||||||
if ([timers objectForKey:currentThread]) // for a pending timer
|
if ([dict objectForKey: timerKey]) // for a pending timer
|
||||||
[NSException raise:NSInternalInconsistencyException
|
[NSException raise:NSInternalInconsistencyException
|
||||||
format:@"Periodic events are already being generated for "
|
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
|
// If the delay time is 0 then register
|
||||||
// a timer immediately. Otherwise
|
// a timer immediately. Otherwise
|
||||||
// register a timer with no repeat that
|
// register a timer with no repeat that
|
||||||
|
@ -223,9 +218,7 @@ NSThread* currentThread = [NSThread currentThread];
|
||||||
|
|
||||||
[[NSRunLoop currentRunLoop] addTimer: timer
|
[[NSRunLoop currentRunLoop] addTimer: timer
|
||||||
forMode: NSEventTrackingRunLoopMode];
|
forMode: NSEventTrackingRunLoopMode];
|
||||||
[timers setObject:timer forKey:currentThread];
|
[dict setObject: timer forKey: timerKey];
|
||||||
|
|
||||||
[timersLock unlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void)_timerFired:(NSTimer*)timer
|
+ (void)_timerFired:(NSTimer*)timer
|
||||||
|
@ -250,7 +243,8 @@ NSEvent* periodicEvent = [self otherEventWithType:NSPeriodic
|
||||||
{ // this method provides a
|
{ // this method provides a
|
||||||
NSTimer* realTimer; // means of delaying the
|
NSTimer* realTimer; // means of delaying the
|
||||||
// start of periodic events
|
// start of periodic events
|
||||||
[timersLock lock];
|
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||||
|
|
||||||
NSDebugLog (@"_registerRealTimer:");
|
NSDebugLog (@"_registerRealTimer:");
|
||||||
|
|
||||||
realTimer = [NSTimer timerWithTimeInterval:[[timer userInfo] doubleValue]
|
realTimer = [NSTimer timerWithTimeInterval:[[timer userInfo] doubleValue]
|
||||||
|
@ -259,28 +253,23 @@ NSTimer* realTimer; // means of delaying the
|
||||||
userInfo:nil
|
userInfo:nil
|
||||||
repeats:YES]; // Add the real timer to the timers
|
repeats:YES]; // Add the real timer to the timers
|
||||||
// dictionary and to the run loop
|
// dictionary and to the run loop
|
||||||
[timers setObject:realTimer forKey:[NSThread currentThread]];
|
/* xxx what if there is already a timer - are we sure there isn't? */
|
||||||
|
[dict setObject: realTimer forKey: timerKey];
|
||||||
[[NSRunLoop currentRunLoop] addTimer: realTimer
|
[[NSRunLoop currentRunLoop] addTimer: realTimer
|
||||||
forMode: NSEventTrackingRunLoopMode];
|
forMode: NSEventTrackingRunLoopMode];
|
||||||
|
|
||||||
[timersLock unlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void)stopPeriodicEvents
|
+ (void)stopPeriodicEvents
|
||||||
{
|
{
|
||||||
NSTimer* timer;
|
NSTimer* timer;
|
||||||
NSThread* currentThread;
|
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
|
||||||
|
|
||||||
NSDebugLog (@"stopPeriodicEvents");
|
NSDebugLog (@"stopPeriodicEvents");
|
||||||
[timersLock lock];
|
|
||||||
|
|
||||||
currentThread = [NSThread currentThread];
|
|
||||||
/* Remove any existing timer for this thread */
|
/* Remove any existing timer for this thread */
|
||||||
timer = [timers objectForKey:currentThread];
|
timer = [dict objectForKey: timerKey];
|
||||||
[timer invalidate];
|
[timer invalidate];
|
||||||
[timers removeObjectForKey:currentThread];
|
[dict removeObjectForKey: timerKey];
|
||||||
|
|
||||||
[timersLock unlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue