mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 01:31:08 +00:00
Lazily initialize POSIX threads, matching OS X behaviour and stopping us from crashing when calling autorelease from a thread that was not previously registered explicitly (yuck!)
Also do some quite hacky (and not totally correct) things to try to make sure that we aren't confused into thinking that the first NSThread is the main thread, if it's created on a separate thread. Currently only supported on FreeBSD and OpenBSD. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33521 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
72b55444fb
commit
6893ce1a95
2 changed files with 20 additions and 6 deletions
|
@ -438,6 +438,7 @@ pop_pool_from_cache (struct autorelease_thread_vars *tv)
|
|||
{
|
||||
NSThread *t = GSCurrentThread();
|
||||
NSAutoreleasePool *pool;
|
||||
NSAssert(nil != t, @"Creating autorelease pool on nonexistent thread!");
|
||||
|
||||
pool = t->_autorelease_vars.current_pool;
|
||||
if (pool == nil && t->_active == NO)
|
||||
|
|
|
@ -84,6 +84,14 @@
|
|||
#include <objc/objc-auto.h>
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__OpenBSD__)
|
||||
# include <pthread_np.h>
|
||||
# define IS_MAIN_PTHREAD (pthread_main_np() == 1)
|
||||
#else
|
||||
# define IS_MAIN_PTHREAD (1)
|
||||
#endif
|
||||
|
||||
|
||||
// Some older BSD systems used a non-standard range of thread priorities.
|
||||
// Use these if they exist, otherwise define standard ones.
|
||||
#ifndef PTHREAD_MAX_PRIORITY
|
||||
|
@ -318,11 +326,17 @@ static void exitedThread(void *thread)
|
|||
inline NSThread*
|
||||
GSCurrentThread(void)
|
||||
{
|
||||
if (defaultThread == nil)
|
||||
NSThread *thr = pthread_getspecific(thread_object_key);
|
||||
if (nil == thr)
|
||||
{
|
||||
[NSThread currentThread];
|
||||
GSRegisterCurrentThread();
|
||||
if ((defaultThread == nil) && IS_MAIN_PTHREAD)
|
||||
{
|
||||
defaultThread = thr;
|
||||
}
|
||||
thr = pthread_getspecific(thread_object_key);
|
||||
}
|
||||
return (NSThread*)pthread_getspecific(thread_object_key);
|
||||
return thr;
|
||||
}
|
||||
|
||||
NSMutableDictionary*
|
||||
|
@ -479,7 +493,7 @@ unregisterActiveThread(NSThread *thread)
|
|||
|
||||
+ (NSThread*) currentThread
|
||||
{
|
||||
return (NSThread*)pthread_getspecific(thread_object_key);
|
||||
return GSCurrentThread();
|
||||
}
|
||||
|
||||
+ (void) detachNewThreadSelector: (SEL)aSelector
|
||||
|
@ -538,8 +552,7 @@ unregisterActiveThread(NSThread *thread)
|
|||
*/
|
||||
threadClass = self;
|
||||
|
||||
[NSThread _createThreadForCurrentPthread];
|
||||
defaultThread = [NSThread currentThread];
|
||||
GSCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue