Some thread safety checks added.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@13583 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-05-03 08:17:04 +00:00
parent 54a2f4a2dd
commit a085710883
3 changed files with 50 additions and 12 deletions

View file

@ -2,7 +2,12 @@
* Source/NSAssertion.m: Added comments and fixed bug in handling
an assertion in a function ... was calling va_end() before the last
use of the arguments.
use of the arguments. Also, release new handler after adding it to
thread dictionary ... fix memory leak.
* Source/NSThread.m: Add fprintf of alert message to STDERR if we
are unable to determine the current thread. Don't attempt to use
NSLog() or similar ... since chances are, without a thread object,
that would just crash.
2002-05-02 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -52,6 +52,7 @@ static NSString *dict_key = @"_NSAssertionHandler";
{
handler = [[NSAssertionHandler alloc] init];
[dict setObject: handler forKey: dict_key];
RELEASE(handler);
}
return handler;
}

View file

@ -83,12 +83,14 @@ static BOOL entered_multi_threaded_state = NO;
*/
static NSThread *defaultThread = nil;
/*
/**
* Fast access function to get current thread.
*/
inline NSThread*
GSCurrentThread()
{
NSThread *t;
if (entered_multi_threaded_state == NO)
{
/*
@ -97,33 +99,48 @@ GSCurrentThread()
*/
if (defaultThread == nil)
{
return [NSThread currentThread];
t = [NSThread currentThread];
}
else
{
return defaultThread;
t = defaultThread;
}
}
else
{
return (NSThread*)objc_thread_get_data();
t = (NSThread*)objc_thread_get_data();
if (t == nil)
{
fprintf(stderr, "ALERT ... GSCurrentThread() ... the "
"objc_thread_get_data() call returned nil!");
fflush(stderr); // Needed for windoze
}
}
return t;
}
/*
/**
* Fast access function for thread dictionary of current thread.
*/
NSMutableDictionary*
GSCurrentThreadDictionary()
{
NSThread *thread = GSCurrentThread();
NSMutableDictionary *dict = thread->_thread_dictionary;
if (dict == nil)
if (thread == nil)
{
dict = [thread threadDictionary];
return nil;
}
else
{
NSMutableDictionary *dict = thread->_thread_dictionary;
if (dict == nil)
{
dict = [thread threadDictionary];
}
return dict;
}
return dict;
}
/*
@ -159,18 +176,33 @@ gnustep_base_thread_callback()
*/
+ (NSThread*) currentThread
{
NSThread *t;
if (entered_multi_threaded_state == NO)
{
/*
* The NSThread class has been initialized - so we will have a default
* thread set up.
*/
return defaultThread;
t = defaultThread;
if (t == nil)
{
fprintf(stderr, "ALERT ... [NSThread +currentThread] ... the "
"default thread is nil!");
fflush(stderr); // Needed for windoze
}
}
else
{
return (NSThread*)objc_thread_get_data();
t = (NSThread*)objc_thread_get_data();
if (t == nil)
{
fprintf(stderr, "ALERT ... [NSThread +currentThread] ... the "
"objc_thread_get_data() call returned nil!");
fflush(stderr); // Needed for windoze
}
}
return t;
}
/*