mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
Methods to register/unregister an alien thread turned into functions
for maximum thread safety git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9449 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a3939e6bed
commit
8dfbba6d5a
3 changed files with 51 additions and 24 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2001-03-19 Nicola Pero <nicola@brainstorm.co.uk>
|
||||
|
||||
* Source/NSThread.m: registerCurrentThread and
|
||||
unregisterCurrentThread turned into functions - called
|
||||
GSRegisterCurrentThread and GSUnregisterCurrentThread.
|
||||
* Headers/gnustep/base/NSThread.h: Updated for change.
|
||||
|
||||
* Source/NSThread.m (GSRegisterCurrentThread): Call
|
||||
objc_thread_add before creating the NSThread object using a method
|
||||
call.
|
||||
|
||||
2001-03-19 Jonathan Gapen <jagapen@home.com>
|
||||
|
||||
* Source/NSString.m: In ([-rangeOfComposedCharacterSequenceAtIndex:]),
|
||||
|
|
|
@ -66,9 +66,9 @@ typedef enum
|
|||
|
||||
#ifndef NO_GNUSTEP
|
||||
/*
|
||||
* Don't use the following methods unless you really know what you are
|
||||
* Don't use the following functions unless you really know what you are
|
||||
* doing !
|
||||
* The following methods are low-levelish and special.
|
||||
* The following functions are low-levelish and special.
|
||||
* They are meant to make it possible to run GNUstep code in threads
|
||||
* created in completely different environment, eg inside a JVM.
|
||||
*
|
||||
|
@ -77,26 +77,24 @@ typedef enum
|
|||
* other thread. To initialize NSThread, simply call GSCurrentThread
|
||||
* (). The main thread will not need to be registered.
|
||||
*/
|
||||
@interface NSThread (GNUstepRegister)
|
||||
|
||||
/*
|
||||
* Register an external thread (created using your OS thread interface
|
||||
* directly) to GNUstep. This means that it creates a NSThread object
|
||||
* corresponding to the current thread, and sets things up so that you
|
||||
* can run GNUstep code inside the thread. If the thread was not
|
||||
* known to GNUstep, this methods registers it, and returns YES. If
|
||||
* the thread was already known to GNUstep, this method does nothing
|
||||
* known to GNUstep, this function registers it, and returns YES. If
|
||||
* the thread was already known to GNUstep, this function does nothing
|
||||
* and returns NO. */
|
||||
+ (BOOL) registerCurrentThread;
|
||||
GS_EXPORT BOOL GSRegisterCurrentThread (void);
|
||||
/*
|
||||
* Unregister the current thread from GNUstep. You must only
|
||||
* unregister threads which have been register using + (BOOL)
|
||||
* registerCurrentThread. This method is basically the same as
|
||||
* unregister threads which have been register using
|
||||
* registerCurrentThread (). This method is basically the same as
|
||||
* `+exit', but does not exit the thread - just destroys all objects
|
||||
* associated with the thread. Warning: using any GNUstep code after
|
||||
* this method call is not safe.
|
||||
*/
|
||||
+ (void) unregisterCurrentThread;
|
||||
@end
|
||||
* this method call is not safe. */
|
||||
GS_EXPORT void GSUnregisterCurrentThread (void);
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSNotificationQueue.h>
|
||||
|
||||
static Class threadClass = Nil;
|
||||
|
||||
#ifndef NO_GNUSTEP
|
||||
#ifndef HAVE_OBJC_THREAD_ADD
|
||||
/* We need to access these private vars in the objc runtime - because
|
||||
|
@ -265,6 +267,7 @@ gnustep_base_thread_callback()
|
|||
withObject: nil];
|
||||
defaultThread->_active = YES;
|
||||
objc_thread_set_data(defaultThread);
|
||||
threadClass = self;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,7 +422,22 @@ gnustep_base_thread_callback()
|
|||
@end
|
||||
|
||||
@implementation NSThread (GNUstepRegister)
|
||||
#warning "NSThread +registerCurrentThread will be removed in 1.0.0"
|
||||
/* Deprecated - will be removed in 1.0.0 */
|
||||
+ (BOOL) registerCurrentThread
|
||||
{
|
||||
return GSRegisterCurrentThread ();
|
||||
}
|
||||
|
||||
/* Deprecated - will be removed in 1.0.0 */
|
||||
+ (void) unregisterCurrentThread
|
||||
{
|
||||
GSUnregisterCurrentThread ();
|
||||
}
|
||||
@end
|
||||
|
||||
BOOL
|
||||
GSRegisterCurrentThread (void)
|
||||
{
|
||||
NSThread *thread;
|
||||
|
||||
|
@ -431,19 +449,20 @@ gnustep_base_thread_callback()
|
|||
return NO;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the new thread object.
|
||||
*/
|
||||
thread = (NSThread*)NSAllocateObject (self, 0, NSDefaultMallocZone ());
|
||||
thread = [thread _initWithSelector: NULL toTarget: nil withObject: nil];
|
||||
objc_thread_set_data (thread);
|
||||
((NSThread *)thread)->_active = YES;
|
||||
|
||||
/*
|
||||
* Make sure the Objective-C runtime knows there is an additional thread.
|
||||
*/
|
||||
objc_thread_add ();
|
||||
|
||||
/*
|
||||
* Create the new thread object.
|
||||
*/
|
||||
thread = (NSThread*)NSAllocateObject (threadClass, 0,
|
||||
NSDefaultMallocZone ());
|
||||
thread = [thread _initWithSelector: NULL toTarget: nil withObject: nil];
|
||||
objc_thread_set_data (thread);
|
||||
((NSThread *)thread)->_active = YES;
|
||||
|
||||
/*
|
||||
* We post the notification after we register the thread.
|
||||
*/
|
||||
|
@ -452,12 +471,13 @@ gnustep_base_thread_callback()
|
|||
return YES;
|
||||
}
|
||||
|
||||
+ (void) unregisterCurrentThread
|
||||
void
|
||||
GSUnregisterCurrentThread (void)
|
||||
{
|
||||
NSThread *thread;
|
||||
|
||||
thread = GSCurrentThread();
|
||||
|
||||
|
||||
if (thread->_active == YES)
|
||||
{
|
||||
/*
|
||||
|
@ -478,5 +498,3 @@ gnustep_base_thread_callback()
|
|||
objc_thread_remove ();
|
||||
}
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in a new issue