Differences From Artifact [d3c798f275]:
- File src/OFBlock.m — part of check-in [4fbdca698c] at 2020-11-07 20:23:04 on branch trunk — OFObject: Remove -[allocMemoryWithSize:] (user: js, size: 12095) [annotate] [blame] [check-ins using] [more...]
To Artifact [ada45ac629]:
- File
src/OFBlock.m
— part of check-in
[5b37fbeb82]
at
2020-12-20 21:26:08
on branch trunk
— Return error instead of using errno for threading
errno is problematic for Amiga libraries and is also not thread-safe on
some systems, even though it should. (user: js, size: 12179) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
189 190 191 192 193 194 195 | if ([(id)block isMemberOfClass: (Class)&_NSConcreteMallocBlock]) { #ifdef OF_HAVE_ATOMIC_OPS of_atomic_int_inc(&block->flags); #else unsigned hash = SPINLOCK_HASH(block); | | | | 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | if ([(id)block isMemberOfClass: (Class)&_NSConcreteMallocBlock]) { #ifdef OF_HAVE_ATOMIC_OPS of_atomic_int_inc(&block->flags); #else unsigned hash = SPINLOCK_HASH(block); OF_ENSURE(of_spinlock_lock(&blockSpinlocks[hash]) == 0); block->flags++; OF_ENSURE(of_spinlock_unlock(&blockSpinlocks[hash]) == 0); #endif } return block; } void |
︙ | ︙ | |||
216 217 218 219 220 221 222 | block->descriptor->dispose_helper(block); free(block); } #else unsigned hash = SPINLOCK_HASH(block); | | | | | 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 | block->descriptor->dispose_helper(block); free(block); } #else unsigned hash = SPINLOCK_HASH(block); OF_ENSURE(of_spinlock_lock(&blockSpinlocks[hash]) == 0); if ((--block->flags & OF_BLOCK_REFCOUNT_MASK) == 0) { OF_ENSURE(of_spinlock_unlock(&blockSpinlocks[hash]) == 0); if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE) block->descriptor->dispose_helper(block); free(block); return; } OF_ENSURE(of_spinlock_unlock(&blockSpinlocks[hash]) == 0); #endif } void _Block_object_assign(void *dst_, const void *src_, const int flags_) { int flags = flags_ & (OF_BLOCK_FIELD_IS_BLOCK | |
︙ | ︙ | |||
281 282 283 284 285 286 287 | free(*dst); *dst = src->forwarding; } #else unsigned hash = SPINLOCK_HASH(src); | | > | | | | 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | free(*dst); *dst = src->forwarding; } #else unsigned hash = SPINLOCK_HASH(src); OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash]) == 0); if (src->forwarding == src) src->forwarding = *dst; else { src->byref_dispose(*dst); free(*dst); *dst = src->forwarding; } OF_ENSURE( of_spinlock_unlock(&byrefSpinlocks[hash]) == 0); #endif } else *dst = src; #ifdef OF_HAVE_ATOMIC_OPS of_atomic_int_inc(&(*dst)->flags); #else unsigned hash = SPINLOCK_HASH(*dst); OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash]) == 0); (*dst)->flags++; OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash]) == 0); #endif break; } } void _Block_object_dispose(const void *object_, const int flags_) |
︙ | ︙ | |||
341 342 343 344 345 346 347 | object->byref_dispose(object); free(object); } #else unsigned hash = SPINLOCK_HASH(object); | | > | | | | | 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | object->byref_dispose(object); free(object); } #else unsigned hash = SPINLOCK_HASH(object); OF_ENSURE(of_spinlock_lock(&byrefSpinlocks[hash]) == 0); if ((--object->flags & OF_BLOCK_REFCOUNT_MASK) == 0) { OF_ENSURE( of_spinlock_unlock(&byrefSpinlocks[hash]) == 0); if (object->flags & OF_BLOCK_HAS_COPY_DISPOSE) object->byref_dispose(object); free(object); } OF_ENSURE(of_spinlock_unlock(&byrefSpinlocks[hash]) == 0); #endif break; } } @implementation OFBlock + (void)load { #ifndef OF_HAVE_ATOMIC_OPS for (size_t i = 0; i < NUM_SPINLOCKS; i++) if (of_spinlock_new(&blockSpinlocks[i]) != 0 || of_spinlock_new(&byrefSpinlocks[i]) != 0) @throw [OFInitializationFailedException exceptionWithClass: self]; #endif #ifdef OF_APPLE_RUNTIME Class tmp; |
︙ | ︙ |