Threading fix.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3132 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1998-10-27 15:06:07 +00:00
parent bbef3a7d03
commit 4250e4a439
2 changed files with 11 additions and 30 deletions

View file

@ -4,6 +4,8 @@ Tue Oct 27 15:20:00 1998 Richard Frith-Macdonald <richard@brainstorm.co.uk>
complient and less inefficient.
* Source/NSEvent.m: Fixed per-thread code to be OpenStep complient
and less inefficient.
* Source/NSView.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>

View file

@ -48,8 +48,7 @@
@implementation NSView
/* Class variables */
static NSMutableDictionary *gnustep_gui_nsview_thread_dict = nil;
static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
static NSString *nsview_thread_key = @"NSViewThreadKey";
+ (void)initialize
{
@ -59,12 +58,6 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
// Initial version
[self setVersion:1];
// Allocate dictionary for maintaining
// mapping of threads to focused views
gnustep_gui_nsview_thread_dict = [NSMutableDictionary new];
// Create lock for serializing access to dictionary
gnustep_gui_nsview_lock = [[NSRecursiveLock alloc] init];
}
}
@ -73,53 +66,39 @@ static NSRecursiveLock *gnustep_gui_nsview_lock = nil;
//
+ (void)pushFocusView:(NSView *)focusView
{
NSThread *current_thread = [NSThread currentThread];
// Obtain lock so we can edit the dictionary
[gnustep_gui_nsview_lock lock];
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
// If no context then remove from dictionary
if (!focusView)
{
[gnustep_gui_nsview_thread_dict removeObjectForKey: current_thread];
[dict removeObjectForKey: nsview_thread_key];
}
else
{
[gnustep_gui_nsview_thread_dict setObject: focusView
forKey: current_thread];
[dict setObject: focusView forKey: nsview_thread_key];
}
[gnustep_gui_nsview_lock unlock];
}
+ (NSView *)popFocusView
{
NSThread *current_thread = [NSThread currentThread];
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
id v;
// Obtain lock so we can edit the dictionary
[gnustep_gui_nsview_lock lock];
// Remove from dictionary
v = [gnustep_gui_nsview_thread_dict objectForKey: current_thread];
[gnustep_gui_nsview_thread_dict removeObjectForKey: current_thread];
v = [dict objectForKey: nsview_thread_key];
[dict removeObjectForKey: nsview_thread_key];
[gnustep_gui_nsview_lock unlock];
return v;
}
+ (NSView *)focusView
{
NSThread *current_thread = [NSThread currentThread];
NSMutableDictionary *dict = [[NSThread currentThread] threadDictionary];
NSView *current_view = nil;
// Get focused view for current thread
[gnustep_gui_nsview_lock lock];
// current_view is nil if no focused view
current_view = [gnustep_gui_nsview_thread_dict objectForKey: current_thread];
[gnustep_gui_nsview_lock unlock];
current_view = [dict objectForKey: nsview_thread_key];
return current_view;
}