Make -setNeedsDiplay: and -setNeedsDisplayInRect: thread safe.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16390 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2003-04-08 00:17:53 +00:00
parent c0587cf573
commit 3061f81c4e
3 changed files with 56 additions and 0 deletions

View file

@ -1,3 +1,11 @@
2003-04-08 02:12 Alexander Malmberg <alexander@malmberg.org>
* Source/NSApplication.m: Note which thread is the -gui thread.
* Source/NSView.m (-setNeedsDisplay:, -setNeedsDisplayInRect:):
If the current thread isn't the -gui thread, perform the call
in the main thread instead.
2003-04-07 13:05 Alexander Malmberg <alexander@malmberg.org>
* Source/NSFont.m (-initWithName:matrix:fix:screenFont:): Release

View file

@ -72,6 +72,9 @@
#include <AppKit/GSGuiPrivate.h>
#include <AppKit/GSInfoPanel.h>
/* The -gui thread. See the comment in initialize_gnustep_backend. */
NSThread *GSAppKitThread;
/*
* Base library exception handler
*/
@ -157,6 +160,14 @@ initialize_gnustep_backend(void)
{
Class backend;
/*
Remember which thread we are running in. This thread will be the
-gui thread, ie. the only thread that may do any rendering. With
the exception of a few methods explicitly marked as thread-safe,
other threads should not call any methods in -gui.
*/
GSAppKitThread = [NSThread currentThread];
first = 0;
#ifdef BACKEND_BUNDLE
{

View file

@ -2082,8 +2082,28 @@ GSSetDragTypes(NSView* obj, NSArray *types)
return _visibleRect;
}
extern NSThread *GSAppKitThread; /* TODO */
- (void) _setNeedsDisplay_helper: (NSNumber *)v
{
[self setNeedsDisplay: [v boolValue]];
}
/**
* As an exception to the general rules for threads and -gui, this
* method is thread-safe and may be called from any thread.
*/
- (void) setNeedsDisplay: (BOOL)flag
{
if (GSCurrentThread() != GSAppKitThread)
{
[self performSelectorOnMainThread: @selector(_setNeedsDisplay_helper:)
withObject: [NSNumber numberWithBool: flag]
waitUntilDone: NO];
return;
}
if (flag)
{
[self setNeedsDisplayInRect: _bounds];
@ -2095,15 +2115,32 @@ GSSetDragTypes(NSView* obj, NSArray *types)
}
}
- (void) _setNeedsDisplayInRect_helper: (NSValue *)v
{
[self setNeedsDisplayInRect: [v rectValue]];
}
/**
* Inform the view system that the specified rectangle is invalid and
* requires updating. This automatically informs any superviews of
* any updating they need to do.
*
* As an exception to the general rules for threads and -gui, this
* method is thread-safe and may be called from any thread.
*/
- (void) setNeedsDisplayInRect: (NSRect)invalidRect
{
NSView *currentView = _super_view;
if (GSCurrentThread() != GSAppKitThread)
{
[self performSelectorOnMainThread: @selector(_setNeedsDisplayInRect_helper:)
withObject: [NSValue valueWithRect: invalidRect]
waitUntilDone: NO];
return;
}
/*
* Limit to bounds, combine with old _invalidRect, and then check to see
* if the result is the same as the old _invalidRect - if it isn't then