Differences From Artifact [6195775ed5]:
- File src/runtime/property.m — part of check-in [8f271bed22] at 2020-12-20 03:06:55 on branch trunk — Let OF_ENSURE use OBJC_ERROR in runtime (user: js, size: 5556) [annotate] [blame] [check-ins using] [more...]
To Artifact [ead25184a1]:
- File
src/runtime/property.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: 5600) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
29 30 31 32 33 34 35 | static of_spinlock_t spinlocks[NUM_SPINLOCKS]; #endif #ifdef OF_HAVE_THREADS OF_CONSTRUCTOR() { for (size_t i = 0; i < NUM_SPINLOCKS; i++) | | | | | | | 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 | static of_spinlock_t spinlocks[NUM_SPINLOCKS]; #endif #ifdef OF_HAVE_THREADS OF_CONSTRUCTOR() { for (size_t i = 0; i < NUM_SPINLOCKS; i++) if (of_spinlock_new(&spinlocks[i]) != 0) OBJC_ERROR("Failed to initialize spinlocks!"); } #endif id objc_getProperty(id self, SEL _cmd, ptrdiff_t offset, bool atomic) { if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(ptr); OF_ENSURE(of_spinlock_lock(&spinlocks[hash]) == 0); @try { return [[*ptr retain] autorelease]; } @finally { OF_ENSURE(of_spinlock_unlock(&spinlocks[hash]) == 0); } #else return [[*ptr retain] autorelease]; #endif } return *(id *)(void *)((char *)self + offset); } void objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id value, bool atomic, signed char copy) { if (atomic) { id *ptr = (id *)(void *)((char *)self + offset); #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(ptr); OF_ENSURE(of_spinlock_lock(&spinlocks[hash]) == 0); @try { #endif id old = *ptr; switch (copy) { case 0: *ptr = [value retain]; break; case 2: *ptr = [value mutableCopy]; break; default: *ptr = [value copy]; } [old release]; #ifdef OF_HAVE_THREADS } @finally { OF_ENSURE(of_spinlock_unlock(&spinlocks[hash]) == 0); } #endif return; } id *ptr = (id *)(void *)((char *)self + offset); |
︙ | ︙ | |||
117 118 119 120 121 122 123 | objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic, bool strong) { if (atomic) { #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(src); | | | | | | 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | objc_getPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic, bool strong) { if (atomic) { #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(src); OF_ENSURE(of_spinlock_lock(&spinlocks[hash]) == 0); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS OF_ENSURE(of_spinlock_unlock(&spinlocks[hash]) == 0); #endif return; } memcpy(dest, src, size); } void objc_setPropertyStruct(void *dest, const void *src, ptrdiff_t size, bool atomic, bool strong) { if (atomic) { #ifdef OF_HAVE_THREADS unsigned hash = SPINLOCK_HASH(src); OF_ENSURE(of_spinlock_lock(&spinlocks[hash]) == 0); #endif memcpy(dest, src, size); #ifdef OF_HAVE_THREADS OF_ENSURE(of_spinlock_unlock(&spinlocks[hash]) == 0); #endif return; } memcpy(dest, src, size); } |
︙ | ︙ |