mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Notification handling improvements.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@4455 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d622f33322
commit
defe7790dc
3 changed files with 65 additions and 12 deletions
|
@ -1,3 +1,9 @@
|
|||
Tue Jun 22 16:15:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSThread.m: Various changes to tidy up notification handling
|
||||
to avoid warning messages and to ensure that observers get notified
|
||||
before the application becomes multi-threaded.
|
||||
|
||||
Mon Jun 21 20:55:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
|
||||
* Source/NSFileManager.m: Fixed error recursing into directory.
|
||||
|
|
|
@ -478,6 +478,30 @@ GSIMapNodeForKey(GSIMapTable map, GSIMapKey key)
|
|||
return node;
|
||||
}
|
||||
|
||||
#if (GSI_MAP_KTYPES & GSUNION_INT)
|
||||
/*
|
||||
* Specialized lookup for the case where keys are known to be simple integer
|
||||
* or pointer values that are their own hash values and con be compared with
|
||||
* a test for integer equality.
|
||||
*/
|
||||
static INLINE GSIMapNode
|
||||
GSIMapNodeForSimpleKey(GSIMapTable map, GSIMapKey key)
|
||||
{
|
||||
GSIMapBucket bucket;
|
||||
GSIMapNode node;
|
||||
|
||||
if (map->nodeCount == 0)
|
||||
return 0;
|
||||
bucket = map->buckets + key.uint % map->bucketCount;
|
||||
node = bucket->firstNode;
|
||||
while ((node != 0) && node->key.uint != key.uint)
|
||||
{
|
||||
node = node->nextInBucket;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
#endif
|
||||
|
||||
static INLINE void
|
||||
GSIMapResize(GSIMapTable map, size_t new_capacity)
|
||||
{
|
||||
|
|
|
@ -71,15 +71,22 @@ GSCurrentThreadDictionary()
|
|||
|
||||
void gnustep_base_thread_callback()
|
||||
{
|
||||
/* Post a notification if this is the first new thread to be created.
|
||||
Won't work properly if threads are not all created by this class.
|
||||
*/
|
||||
/*
|
||||
* Post a notification if this is the first new thread to be created.
|
||||
* Won't work properly if threads are not all created by this class,
|
||||
* but it's better than nothing.
|
||||
*/
|
||||
if (!entered_multi_threaded_state)
|
||||
{
|
||||
NSNotification *n;
|
||||
|
||||
entered_multi_threaded_state = YES;
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: NSWillBecomeMultiThreadedNotification
|
||||
object: nil];
|
||||
n = [NSNotification alloc];
|
||||
n = [n initWithName: NSWillBecomeMultiThreadedNotification
|
||||
object: nil
|
||||
userInfo: nil];
|
||||
[[NSNotificationCenter defaultCenter] postNotification: n];
|
||||
RELEASE(n);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,6 +99,12 @@ void gnustep_base_thread_callback()
|
|||
if (self == [NSThread class])
|
||||
{
|
||||
entered_multi_threaded_state = NO;
|
||||
/*
|
||||
* The objc runtime calls this callback AFTER creating a new thread -
|
||||
* which is not correct for us, but does at least mean that we can tell
|
||||
* if we have become multi-threaded due to a call to the runtime directly
|
||||
* rather than via the NSThread class.
|
||||
*/
|
||||
objc_set_thread_callback(gnustep_base_thread_callback);
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +126,7 @@ void gnustep_base_thread_callback()
|
|||
/* initialize our ivars. */
|
||||
_thread_dictionary = nil; // Initialize this later only when needed
|
||||
_exception_handler = NULL;
|
||||
init_autorelease_thread_vars (&_autorelease_vars);
|
||||
init_autorelease_thread_vars(&_autorelease_vars);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -130,7 +143,13 @@ void gnustep_base_thread_callback()
|
|||
toTarget: (id)aTarget
|
||||
withObject: (id)anArgument
|
||||
{
|
||||
// Have the runtime detach the thread
|
||||
/*
|
||||
* Make sure the notification is posted BEFORE the new thread starts.
|
||||
*/
|
||||
gnustep_base_thread_callback();
|
||||
/*
|
||||
* Have the runtime detach the thread
|
||||
*/
|
||||
if (objc_thread_detach (aSelector, aTarget, anArgument) == NULL)
|
||||
{
|
||||
/* This should probably be an exception */
|
||||
|
@ -208,15 +227,19 @@ void gnustep_base_thread_callback()
|
|||
// What happens if the thread doesn't call +exit?
|
||||
+ (void) exit
|
||||
{
|
||||
NSThread *t;
|
||||
NSThread *t;
|
||||
NSNotification *n;
|
||||
|
||||
// the current NSThread
|
||||
t = GSCurrentThread();
|
||||
|
||||
// Post the notification
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: NSThreadWillExitNotification
|
||||
object: t];
|
||||
n = [NSNotification alloc];
|
||||
n = [n initWithName: NSThreadWillExitNotification
|
||||
object: t
|
||||
userInfo: nil];
|
||||
[[NSNotificationCenter defaultCenter] postNotification: n];
|
||||
RELEASE(n);
|
||||
|
||||
/*
|
||||
* Release anything in our autorelease pools
|
||||
|
|
Loading…
Reference in a new issue