︙ | | |
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
-
+
-
+
|
#import "OFBlock.h"
#import "OFAllocFailedException.h"
#import "OFInitializationFailedException.h"
#import "macros.h"
#ifdef OF_ATOMIC_OPS
#ifdef OF_HAVE_ATOMIC_OPS
# import "atomic.h"
#endif
#ifdef OF_THREADS
#ifdef OF_HAVE_THREADS
# import "threading.h"
#endif
typedef struct of_block_byref_t of_block_byref_t;
struct of_block_byref_t {
Class isa;
of_block_byref_t *forwarding;
|
︙ | | |
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
|
-
+
|
# endif
#endif
static struct {
Class isa;
} alloc_failed_exception;
#if !defined(OF_ATOMIC_OPS) && defined(OF_THREADS)
#ifndef OF_HAVE_ATOMIC_OPS
# define NUM_SPINLOCKS 8 /* needs to be a power of 2 */
# define SPINLOCK_HASH(p) ((uintptr_t)p >> 4) & (NUM_SPINLOCKS - 1)
static of_spinlock_t spinlocks[NUM_SPINLOCKS];
#endif
void*
_Block_copy(const void *block_)
|
︙ | | |
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
-
+
|
if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE)
block->descriptor->copy_helper(copy, block);
return copy;
}
if (object_getClass((id)block) == (Class)&_NSConcreteMallocBlock) {
#if defined(OF_ATOMIC_OPS)
#ifdef OF_HAVE_ATOMIC_OPS
of_atomic_inc_int(&block->flags);
#else
unsigned hash = SPINLOCK_HASH(block);
OF_ENSURE(of_spinlock_lock(&spinlocks[hash]));
block->flags++;
OF_ENSURE(of_spinlock_unlock(&spinlocks[hash]));
|
︙ | | |
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
-
+
|
_Block_release(const void *block_)
{
of_block_literal_t *block = (of_block_literal_t*)block_;
if (object_getClass((id)block) != (Class)&_NSConcreteMallocBlock)
return;
#ifdef OF_ATOMIC_OPS
#ifdef OF_HAVE_ATOMIC_OPS
if ((of_atomic_dec_int(&block->flags) & OF_BLOCK_REFCOUNT_MASK) == 0) {
if (block->flags & OF_BLOCK_HAS_COPY_DISPOSE)
block->descriptor->dispose_helper(block);
free(block);
}
#else
|
︙ | | |
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
-
+
|
memcpy(&_NSConcreteMallocBlock, tmp, sizeof(_NSConcreteMallocBlock));
free(tmp);
objc_registerClassPair((Class)&_NSConcreteMallocBlock);
# endif
}
#endif
#if !defined(OF_ATOMIC_OPS)
#ifndef OF_HAVE_ATOMIC_OPS
+ (void)initialize
{
size_t i;
for (i = 0; i < NUM_SPINLOCKS; i++)
if (!of_spinlock_new(&spinlocks[i]))
@throw [OFInitializationFailedException
|
︙ | | |