Overview
Comment: | Use @synchronized over OFMutex in a few places
These places are not super performance critical and the code becomes a Actually using @synchronized in ObjFW itself is also a good motivation |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
ff3a60cc123ed3f67403e8f233dae5df |
User & Date: | js on 2024-04-28 08:36:55 |
Other Links: | manifest | tags |
Context
2024-04-28
| ||
11:56 | Workaround for OFSubprocessTests on Windows 9x check-in: cd829b4336 user: js tags: trunk | |
08:36 | Use @synchronized over OFMutex in a few places check-in: ff3a60cc12 user: js tags: trunk | |
2024-04-27
| ||
01:55 | GitHub Actions: Replace macos-latest with macos-12 check-in: 799dbd0e16 user: js tags: trunk | |
Changes
Modified src/OFDate.m from [ae00d275b0] to [2047693bf0].
︙ | ︙ | |||
297 298 299 300 301 302 303 | } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end | < | 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | } #ifdef __clang__ # pragma clang diagnostic pop #endif OF_SINGLETON_METHODS @end @implementation OFDate + (void)initialize { #ifdef OF_WINDOWS HMODULE module; #endif |
︙ | ︙ |
Modified src/OFIRIHandler.m from [55f4357182] to [922d7f84e3].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #include "config.h" #import "OFIRIHandler.h" #import "OFDictionary.h" #import "OFIRI.h" #import "OFNumber.h" | < < < < < < < < < < < < < < < < < < < < | < < < < < < < | < < < < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | #include "config.h" #import "OFIRIHandler.h" #import "OFDictionary.h" #import "OFIRI.h" #import "OFNumber.h" #import "OFArchiveIRIHandler.h" #import "OFEmbeddedIRIHandler.h" #ifdef OF_HAVE_FILES # import "OFFileIRIHandler.h" #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) # import "OFHTTPIRIHandler.h" #endif #import "OFUnsupportedProtocolException.h" static OFMutableDictionary OF_GENERIC(OFString *, OFIRIHandler *) *handlers; @implementation OFIRIHandler @synthesize scheme = _scheme; + (void)initialize { if (self != [OFIRIHandler class]) return; handlers = [[OFMutableDictionary alloc] init]; [self registerClass: [OFEmbeddedIRIHandler class] forScheme: @"embedded"]; #ifdef OF_HAVE_FILES [self registerClass: [OFFileIRIHandler class] forScheme: @"file"]; #endif #if defined(OF_HAVE_SOCKETS) && defined(OF_HAVE_THREADS) [self registerClass: [OFHTTPIRIHandler class] forScheme: @"http"]; [self registerClass: [OFHTTPIRIHandler class] forScheme: @"https"]; #endif [self registerClass: [OFArchiveIRIHandler class] forScheme: @"gzip"]; [self registerClass: [OFArchiveIRIHandler class] forScheme: @"lha"]; [self registerClass: [OFArchiveIRIHandler class] forScheme: @"tar"]; [self registerClass: [OFArchiveIRIHandler class] forScheme: @"zip"]; [self registerClass: [OFArchiveIRIHandler class] forScheme: @"zoo"]; } + (bool)registerClass: (Class)class forScheme: (OFString *)scheme { @synchronized (handlers) { OFIRIHandler *handler; if ([handlers objectForKey: scheme] != nil) return false; handler = [[class alloc] initWithScheme: scheme]; @try { [handlers setObject: handler forKey: scheme]; } @finally { [handler release]; } } return true; } + (OFIRIHandler *)handlerForIRI: (OFIRI *)IRI { OF_KINDOF(OFIRIHandler *) handler; @synchronized (handlers) { handler = [handlers objectForKey: IRI.scheme]; } if (handler == nil) @throw [OFUnsupportedProtocolException exceptionWithIRI: IRI]; return handler; } |
︙ | ︙ |
Modified src/OFKernelEventObserver.h from [d4eaadb46a] to [15425300f6].
︙ | ︙ | |||
27 28 29 30 31 32 33 | # include <exec/tasks.h> #endif OF_ASSUME_NONNULL_BEGIN @class OFMutableArray OF_GENERIC(ObjectType); @class OFDate; | < < < | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | # include <exec/tasks.h> #endif OF_ASSUME_NONNULL_BEGIN @class OFMutableArray OF_GENERIC(ObjectType); @class OFDate; @class OFMutableData; /** * @protocol OFKernelEventObserverDelegate * OFKernelEventObserver.h ObjFW/OFKernelEventObserver.h * * @brief A protocol that needs to be implemented by delegates for |
︙ | ︙ |
Modified src/OFNotificationCenter.h from [42748590cb] to [ca155ce1ef].
︙ | ︙ | |||
19 20 21 22 23 24 25 | #import "OFObject.h" #import "OFNotification.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); | < < < | 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #import "OFObject.h" #import "OFNotification.h" OF_ASSUME_NONNULL_BEGIN @class OFMutableDictionary OF_GENERIC(KeyType, ObjectType); #ifdef OF_HAVE_BLOCKS /** * @brief A block which is called when a notification has been posted. * * @param notification The notification that has been posted */ |
︙ | ︙ | |||
43 44 45 46 47 48 49 | * @brief A class to send and register for notifications. */ #ifndef OF_NOTIFICATION_CENTER_M OF_SUBCLASSING_RESTRICTED #endif @interface OFNotificationCenter: OFObject { | < < < | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | * @brief A class to send and register for notifications. */ #ifndef OF_NOTIFICATION_CENTER_M OF_SUBCLASSING_RESTRICTED #endif @interface OFNotificationCenter: OFObject { OFMutableDictionary *_handles; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFNotificationCenter *defaultCenter; #endif |
︙ | ︙ |
Modified src/OFNotificationCenter.m from [acdacb86e1] to [eb7640502b].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #define OF_NOTIFICATION_CENTER_M #include "config.h" #import "OFNotificationCenter.h" #import "OFArray.h" #import "OFDictionary.h" | < < < | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #define OF_NOTIFICATION_CENTER_M #include "config.h" #import "OFNotificationCenter.h" #import "OFArray.h" #import "OFDictionary.h" #import "OFSet.h" #import "OFString.h" #import "OFInvalidArgumentException.h" @interface OFDefaultNotificationCenter: OFNotificationCenter @end |
︙ | ︙ | |||
183 184 185 186 187 188 189 | } - (instancetype)init { self = [super init]; @try { | < < < < < < < < < | < < < < | 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | } - (instancetype)init { self = [super init]; @try { _handles = [[OFMutableDictionary alloc] init]; } @catch (id e) { [self release]; @throw e; } return self; } - (void)dealloc { [_handles release]; [super dealloc]; } - (void)of_addObserver: (OFNotificationCenterHandle *)handle { @synchronized (_handles) { OFMutableSet *handlesForName = [_handles objectForKey: handle->_name]; if (handlesForName == nil) { handlesForName = [OFMutableSet set]; [_handles setObject: handlesForName forKey: handle->_name]; } [handlesForName addObject: handle]; } } - (void)addObserver: (id)observer selector: (SEL)selector name: (OFNotificationName)name object: (id)object { |
︙ | ︙ | |||
278 279 280 281 282 283 284 | if (![handle_ isKindOfClass: [OFNotificationCenterHandle class]]) @throw [OFInvalidArgumentException exception]; handle = handle_; pool = objc_autoreleasePoolPush(); | < | | | < < < < < < < < | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | if (![handle_ isKindOfClass: [OFNotificationCenterHandle class]]) @throw [OFInvalidArgumentException exception]; handle = handle_; pool = objc_autoreleasePoolPush(); if (![handle isKindOfClass: [OFNotificationCenterHandle class]]) @throw [OFInvalidArgumentException exception]; @synchronized (_handles) { OFNotificationName name = [[handle->_name copy] autorelease]; OFMutableSet *handlesForName = [_handles objectForKey: name]; [handlesForName removeObject: handle]; if (handlesForName.count == 0) [_handles removeObjectForKey: name]; } objc_autoreleasePoolPop(pool); } - (void)removeObserver: (id)observer selector: (SEL)selector name: (OFNotificationName)name |
︙ | ︙ | |||
325 326 327 328 329 330 331 | } - (void)postNotification: (OFNotification *)notification { void *pool = objc_autoreleasePoolPush(); OFMutableArray *matchedHandles = [OFMutableArray array]; | < < < | < < < < | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | } - (void)postNotification: (OFNotification *)notification { void *pool = objc_autoreleasePoolPush(); OFMutableArray *matchedHandles = [OFMutableArray array]; @synchronized (_handles) { for (OFNotificationCenterHandle *handle in [_handles objectForKey: notification.name]) if (handle->_object == nil || handle->_object == notification.object) [matchedHandles addObject: handle]; } for (OFNotificationCenterHandle *handle in matchedHandles) { #ifdef OF_HAVE_BLOCKS if (handle->_block != NULL) handle->_block(notification); else { #endif |
︙ | ︙ |