discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

thread safe setNeedsDisplay:


From: Pierre-Yves Rivaille
Subject: thread safe setNeedsDisplay:
Date: Wed, 30 Oct 2002 00:36:46 +0100

I've implemented a "thread safe" setNeedsDisplay: (and setNeedsDisplayInRect:).
It behaves as it is supposed to according to the Cocoa doc :
when called from a working thread (i.e. not the first one), the setNeedsDisplay: method behaves as if it had been called from the main thread.

This is done by passing a message from the worker thread to the main thread telling it to call setNeedsDisplay:. However the message is not passed using NSConnection objects as the message needs to be transfered whatever the current runloop mode is (ConnectionReply, DefaultRunLoop, ModalPanelRunLoop or EventTrackingRunLoop). To do so, I've added a GSAppKitInterThreadRunLoopWatcher to the main thread. It does wait on a socket. Whenever a worker thread calls setNeedsDisplay:, the method's arguments are added to an array and one byte is written on the socket. Then the GSAppKitInterThreadRunLoopWatcher reads the method's arguments and call setNeedsDisplay: in the main thread.

The code is not ready for integration is CVS as it is not polished. However I'd like to have some advice on my use of NSRunLoop/GSRunLoopWatcher and on the way the method's call is sent to the main thread.

Here are the 3 patches
<NSApplication.m.patch><NSRunLoop.m.patch><NSView.m.patch>
and a sample program <ThreadTest.tgz>

I hope my explanations were clear enough...

        Pierre-Yves

Attachment: NSApplication.m.patch
Description: Binary data

Attachment: NSRunLoop.m.patch
Description: Binary data

Attachment: NSView.m.patch
Description: Binary data

Attachment: ThreadTest.tgz
Description: GNU Unix tar archive


reply via email to

[Prev in Thread] Current Thread [Next in Thread]