mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Fix indentation.
([NSThread +currentThread]): Add parenthesis around assignment inside while. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1213 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0bf7ab8983
commit
2dfd45f9ec
1 changed files with 88 additions and 88 deletions
|
@ -47,154 +47,154 @@ BOOL ENTERED_MULTI_THREADED_STATE;
|
|||
// Private methods to set/get thread id
|
||||
- (_objc_thread_t)threadId
|
||||
{
|
||||
return thread_id;
|
||||
return thread_id;
|
||||
}
|
||||
|
||||
- (void)setThreadId:(_objc_thread_t)threadId
|
||||
{
|
||||
thread_id = threadId;
|
||||
thread_id = threadId;
|
||||
}
|
||||
|
||||
// Class initialization
|
||||
+ (void)initialize
|
||||
{
|
||||
if (self == [NSThread class])
|
||||
{
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
if (self == [NSThread class])
|
||||
{
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
|
||||
// Allocate global/class variables
|
||||
NSBecomingMultiThreaded = [NSString
|
||||
stringWithCString:"Entering multi-threaded state"];
|
||||
NSThreadExiting = [NSString
|
||||
stringWithCString:"Thread is exiting"];
|
||||
THREAD_LIST = [NSArray array];
|
||||
THREAD_LIST_LOCK = [[NSRecursiveLock alloc] init];
|
||||
[THREAD_LIST_LOCK autorelease];
|
||||
ENTERED_MULTI_THREADED_STATE = NO;
|
||||
}
|
||||
// Allocate global/class variables
|
||||
NSBecomingMultiThreaded = [NSString
|
||||
stringWithCString:"Entering multi-threaded state"];
|
||||
NSThreadExiting = [NSString
|
||||
stringWithCString:"Thread is exiting"];
|
||||
THREAD_LIST = [NSArray array];
|
||||
THREAD_LIST_LOCK = [[NSRecursiveLock alloc] init];
|
||||
[THREAD_LIST_LOCK autorelease];
|
||||
ENTERED_MULTI_THREADED_STATE = NO;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialization
|
||||
- init
|
||||
{
|
||||
[super init];
|
||||
[super init];
|
||||
|
||||
// Thread specific variables
|
||||
thread_dictionary = [NSMutableDictionary dictionary];
|
||||
return self;
|
||||
// Thread specific variables
|
||||
thread_dictionary = [NSMutableDictionary dictionary];
|
||||
return self;
|
||||
}
|
||||
|
||||
// Creating an NSThread
|
||||
+ (NSThread *)currentThread
|
||||
{
|
||||
NSThread *t;
|
||||
_objc_thread_t tid;
|
||||
id e;
|
||||
NSThread *t;
|
||||
_objc_thread_t tid;
|
||||
id e;
|
||||
|
||||
// Get current thread id from runtime
|
||||
tid = objc_thread_id();
|
||||
// Get current thread id from runtime
|
||||
tid = objc_thread_id();
|
||||
|
||||
// Lock the thread list so it doesn't change on us
|
||||
[THREAD_LIST_LOCK lock];
|
||||
// Lock the thread list so it doesn't change on us
|
||||
[THREAD_LIST_LOCK lock];
|
||||
|
||||
// Enumerate through thread list to find the current thread
|
||||
e = [THREAD_LIST objectEnumerator];
|
||||
while (t = [e nextObject])
|
||||
// Enumerate through thread list to find the current thread
|
||||
e = [THREAD_LIST objectEnumerator];
|
||||
while ((t = [e nextObject]))
|
||||
{
|
||||
if ([t threadId] == tid)
|
||||
{
|
||||
if ([t threadId] == tid)
|
||||
{
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
return t;
|
||||
}
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
// Something is wrong if we get here
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
return nil;
|
||||
// Something is wrong if we get here
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (void)detachNewThreadSelector:(SEL)aSelector
|
||||
toTarget:(id)aTarget
|
||||
withObject:(id)anArgument
|
||||
toTarget:(id)aTarget
|
||||
withObject:(id)anArgument
|
||||
{
|
||||
NSThread *t = [[NSThread alloc] init];
|
||||
_objc_thread_t tid;
|
||||
NSThread *t = [[NSThread alloc] init];
|
||||
_objc_thread_t tid;
|
||||
|
||||
// Lock the thread list so it doesn't change on us
|
||||
[THREAD_LIST_LOCK lock];
|
||||
// Lock the thread list so it doesn't change on us
|
||||
[THREAD_LIST_LOCK lock];
|
||||
|
||||
// Have the runtime detach the thread
|
||||
tid = objc_thread_detach(aSelector, aTarget, anArgument);
|
||||
if (!tid)
|
||||
{
|
||||
// Couldn't detach!
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
return;
|
||||
}
|
||||
// Have the runtime detach the thread
|
||||
tid = objc_thread_detach(aSelector, aTarget, anArgument);
|
||||
if (!tid)
|
||||
{
|
||||
// Couldn't detach!
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
return;
|
||||
}
|
||||
|
||||
// Save the thread in our thread list
|
||||
[t setThreadId:tid];
|
||||
[THREAD_LIST addObject:t];
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
// Save the thread in our thread list
|
||||
[t setThreadId:tid];
|
||||
[THREAD_LIST addObject:t];
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
}
|
||||
|
||||
// Querying a thread
|
||||
+ (BOOL)isMultiThreaded
|
||||
{
|
||||
return ENTERED_MULTI_THREADED_STATE;
|
||||
return ENTERED_MULTI_THREADED_STATE;
|
||||
}
|
||||
|
||||
- (NSMutableDictionary *)threadDictionary
|
||||
{
|
||||
return thread_dictionary;
|
||||
return thread_dictionary;
|
||||
}
|
||||
|
||||
// Delaying a thread
|
||||
+ (void)sleepUntilDate:(NSDate *)date
|
||||
{
|
||||
// Do we need some runtime/OS support for this?
|
||||
// Do we need some runtime/OS support for this?
|
||||
}
|
||||
|
||||
// Terminating a thread
|
||||
// What happens if the thread doesn't call +exit?
|
||||
+ (void)exit
|
||||
{
|
||||
NSThread *t;
|
||||
_objc_thread_t tid;
|
||||
id e;
|
||||
BOOL found;
|
||||
NSThread *t;
|
||||
_objc_thread_t tid;
|
||||
id e;
|
||||
BOOL found;
|
||||
|
||||
// Get current thread id from runtime
|
||||
tid = objc_thread_id();
|
||||
// Get current thread id from runtime
|
||||
tid = objc_thread_id();
|
||||
|
||||
// Lock the thread list so it doesn't change on us
|
||||
[THREAD_LIST_LOCK lock];
|
||||
// Lock the thread list so it doesn't change on us
|
||||
[THREAD_LIST_LOCK lock];
|
||||
|
||||
// Enumerate through thread list to find the current thread
|
||||
e = [THREAD_LIST objectEnumerator];
|
||||
found = NO;
|
||||
while ((t = [e nextObject]) && (!found))
|
||||
{
|
||||
if ([t threadId] == tid)
|
||||
found = YES;
|
||||
}
|
||||
// Enumerate through thread list to find the current thread
|
||||
e = [THREAD_LIST objectEnumerator];
|
||||
found = NO;
|
||||
while ((t = [e nextObject]) && (!found))
|
||||
{
|
||||
if ([t threadId] == tid)
|
||||
found = YES;
|
||||
}
|
||||
|
||||
// I hope we found it
|
||||
if (found)
|
||||
{
|
||||
// Remove the thread from the list
|
||||
[THREAD_LIST removeObject: t];
|
||||
// I hope we found it
|
||||
if (found)
|
||||
{
|
||||
// Remove the thread from the list
|
||||
[THREAD_LIST removeObject: t];
|
||||
|
||||
// Release the thread object
|
||||
[t release];
|
||||
}
|
||||
// Release the thread object
|
||||
[t release];
|
||||
}
|
||||
|
||||
// Unlock the thread list
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
// Unlock the thread list
|
||||
[THREAD_LIST_LOCK unlock];
|
||||
|
||||
// Tell the runtime to exit the thread
|
||||
objc_thread_exit();
|
||||
// Tell the runtime to exit the thread
|
||||
objc_thread_exit();
|
||||
}
|
||||
|
||||
@end
|
||||
@end
|
||||
|
|
Loading…
Reference in a new issue