Overview
Comment: | More reliable cleanup on failure in OFMutex and OFTLSKey. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f1d813ef6a71e15ffdb86c82ad07896c |
User & Date: | js on 2010-11-06 11:44:41 |
Other Links: | manifest | tags |
Context
2010-11-06
| ||
13:34 | Handle stream exceptions in OFStreamObserver. check-in: b7767021ca user: js tags: trunk | |
11:44 | More reliable cleanup on failure in OFMutex and OFTLSKey. check-in: f1d813ef6a user: js tags: trunk | |
11:40 | Improve spinlock implementation. check-in: 1edd5313ae user: js tags: trunk | |
Changes
Modified src/OFThread.h from [cc3937ad7a] to [7bb5f669dd].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 | @interface OFTLSKey: OFObject { @public of_tlskey_t key; @protected void (*destructor)(id); of_list_object_t *listobj; } /** * \return A new autoreleased Thread Local Storage key */ + tlsKey; | > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | @interface OFTLSKey: OFObject { @public of_tlskey_t key; @protected void (*destructor)(id); of_list_object_t *listobj; BOOL initialized; } /** * \return A new autoreleased Thread Local Storage key */ + tlsKey; |
︙ | ︙ | |||
165 166 167 168 169 170 171 172 173 174 175 176 177 178 | /** * \brief A class for creating mutual exclusions. */ @interface OFMutex: OFObject { of_mutex_t mutex; } /** * \return A new autoreleased mutex. */ + mutex; | > | 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | /** * \brief A class for creating mutual exclusions. */ @interface OFMutex: OFObject { of_mutex_t mutex; BOOL initialized; } /** * \return A new autoreleased mutex. */ + mutex; |
︙ | ︙ |
Modified src/OFThread.m from [6d911d6e5b] to [8a610bd39b].
︙ | ︙ | |||
237 238 239 240 241 242 243 | self = [super init]; @try { if (!of_tlskey_new(&key)) @throw [OFInitializationFailedException newWithClass: isa]; | | | 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | self = [super init]; @try { if (!of_tlskey_new(&key)) @throw [OFInitializationFailedException newWithClass: isa]; initialized = YES; @synchronized (tlskeys) { listobj = [tlskeys appendObject: self]; } } @catch (id e) { [self release]; @throw e; |
︙ | ︙ | |||
264 265 266 267 268 269 270 | } - (void)dealloc { if (destructor != NULL) destructor(self); | > | | 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | } - (void)dealloc { if (destructor != NULL) destructor(self); if (initialized) of_tlskey_free(key); /* In case we called [self release] in init */ if (listobj != NULL) { @synchronized (tlskeys) { [tlskeys removeListObject: listobj]; } } |
︙ | ︙ | |||
293 294 295 296 297 298 299 300 301 302 303 304 305 306 | if (!of_mutex_new(&mutex)) { Class c = isa; [self release]; @throw [OFInitializationFailedException newWithClass: c]; } return self; } - (void)lock { if (!of_mutex_lock(&mutex)) @throw [OFMutexLockFailedException newWithClass: isa]; | > > | 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | if (!of_mutex_new(&mutex)) { Class c = isa; [self release]; @throw [OFInitializationFailedException newWithClass: c]; } initialized = YES; return self; } - (void)lock { if (!of_mutex_lock(&mutex)) @throw [OFMutexLockFailedException newWithClass: isa]; |
︙ | ︙ | |||
315 316 317 318 319 320 321 | { if (!of_mutex_unlock(&mutex)) @throw [OFMutexUnlockFailedException newWithClass: isa]; } - (void)dealloc { | > | | 318 319 320 321 322 323 324 325 326 327 328 329 330 | { if (!of_mutex_unlock(&mutex)) @throw [OFMutexUnlockFailedException newWithClass: isa]; } - (void)dealloc { if (initialized) of_mutex_free(&mutex); [super dealloc]; } @end |