Differences From Artifact [b522bb5862]:
- File
src/OFThread.m
— part of check-in
[e8f12e5de9]
at
2012-08-11 08:39:32
on branch trunk
— OFThread: Set status before spawning thread.
This way, it's not possible to set the status after the thread has
already set it, though this should only happen if the thread instantly
terminates. (user: js, size: 10494) [annotate] [blame] [check-ins using]
To Artifact [413ce95285]:
- File src/OFThread.m — part of check-in [ead7b7acd3] at 2012-09-09 17:48:39 on branch trunk — Make the main thread an OFThread. (user: js, size: 10824) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
48 49 50 51 52 53 54 | #import "OFThreadJoinFailedException.h" #import "OFThreadStartFailedException.h" #import "OFThreadStillRunningException.h" #import "threading.h" static OFList *TLSKeys; | | > | | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #import "OFThreadJoinFailedException.h" #import "OFThreadStartFailedException.h" #import "OFThreadStillRunningException.h" #import "threading.h" static OFList *TLSKeys; static of_tlskey_t threadSelfKey; static OFThread *mainThread; static id call_main(id object) { OFThread *thread = (OFThread*)object; if (!of_tlskey_set(threadSelfKey, thread)) @throw [OFInitializationFailedException exceptionWithClass: [thread class]]; /* * Nasty workaround for thread implementations which can't return a * value on join. */ |
︙ | ︙ | |||
94 95 96 97 98 99 100 | #endif + (void)initialize { if (self != [OFThread class]) return; | | | 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | #endif + (void)initialize { if (self != [OFThread class]) return; if (!of_tlskey_new(&threadSelfKey)) @throw [OFInitializationFailedException exceptionWithClass: self]; } + thread { return [[[self alloc] init] autorelease]; |
︙ | ︙ | |||
142 143 144 145 146 147 148 | + (id)objectForTLSKey: (OFTLSKey*)key { return [[(id)of_tlskey_get(key->key) retain] autorelease]; } + (OFThread*)currentThread { | | > > > > > | 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | + (id)objectForTLSKey: (OFTLSKey*)key { return [[(id)of_tlskey_get(key->key) retain] autorelease]; } + (OFThread*)currentThread { return [[(id)of_tlskey_get(threadSelfKey) retain] autorelease]; } + (OFThread*)mainThread { return mainThread; } + (void)sleepForTimeInterval: (double)seconds { if (seconds < 0) @throw [OFOutOfRangeException exceptionWithClass: self]; |
︙ | ︙ | |||
198 199 200 201 202 203 204 | + (void)terminate { [self terminateWithObject: nil]; } + (void)terminateWithObject: (id)object { | | > > > > > > > > > > | 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | + (void)terminate { [self terminateWithObject: nil]; } + (void)terminateWithObject: (id)object { OFThread *thread = of_tlskey_get(threadSelfKey); if (thread != nil) { thread->returnValue = [object retain]; [thread handleTermination]; thread->running = OF_THREAD_WAITING_FOR_JOIN; } [OFTLSKey callAllDestructors]; [OFAutoreleasePool _releaseAll]; [thread release]; of_thread_exit(); } + (void)_createMainThread { mainThread = [[OFThread alloc] init]; mainThread->thread = of_thread_current(); if (!of_tlskey_set(threadSelfKey, mainThread)) @throw [OFInitializationFailedException exceptionWithClass: self]; } - initWithObject: (id)object_ { self = [super init]; object = [object_ retain]; |
︙ | ︙ |