56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# define class_getSuperclass class_get_super_class
#endif
struct pre_ivar {
void **memchunks;
size_t memchunks_size;
int32_t retain_count;
#if !defined(OF_ATOMIC_OPS) && defined(OF_THREADS)
of_spinlock_t retain_spinlock;
#endif
};
/* Hopefully no arch needs more than 16 bytes padding */
#define PRE_IVAR_ALIGN ((sizeof(struct pre_ivar) + 15) & ~15)
#define PRE_IVAR ((struct pre_ivar*)((char*)self - PRE_IVAR_ALIGN))
|
|
|
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# define class_getSuperclass class_get_super_class
#endif
struct pre_ivar {
void **memchunks;
size_t memchunks_size;
int32_t retain_count;
#if !defined(OF_ATOMIC_OPS)
of_spinlock_t retain_spinlock;
#endif
};
/* Hopefully no arch needs more than 16 bytes padding */
#define PRE_IVAR_ALIGN ((sizeof(struct pre_ivar) + 15) & ~15)
#define PRE_IVAR ((struct pre_ivar*)((char*)self - PRE_IVAR_ALIGN))
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
@throw (OFAllocFailedException*)&alloc_failed_exception;
}
((struct pre_ivar*)instance)->memchunks = NULL;
((struct pre_ivar*)instance)->memchunks_size = 0;
((struct pre_ivar*)instance)->retain_count = 1;
#if !defined(OF_ATOMIC_OPS) && defined(OF_THREADS)
if (!of_spinlock_new(&((struct pre_ivar*)instance)->retain_spinlock)) {
free(instance);
@throw [OFInitializationFailedException newWithClass: self];
}
#endif
instance = (OFObject*)((char*)instance + PRE_IVAR_ALIGN);
|
|
|
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
@throw (OFAllocFailedException*)&alloc_failed_exception;
}
((struct pre_ivar*)instance)->memchunks = NULL;
((struct pre_ivar*)instance)->memchunks_size = 0;
((struct pre_ivar*)instance)->retain_count = 1;
#if !defined(OF_ATOMIC_OPS)
if (!of_spinlock_new(&((struct pre_ivar*)instance)->retain_spinlock)) {
free(instance);
@throw [OFInitializationFailedException newWithClass: self];
}
#endif
instance = (OFObject*)((char*)instance + PRE_IVAR_ALIGN);
|
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
|
pointer: ptr];
}
- retain
{
#if defined(OF_ATOMIC_OPS)
of_atomic_inc_32(&PRE_IVAR->retain_count);
#elif defined(OF_THREADS)
assert(of_spinlock_lock(&PRE_IVAR->retain_spinlock));
PRE_IVAR->retain_count++;
assert(of_spinlock_unlock(&PRE_IVAR->retain_spinlock));
#else
PRE_IVAR->retain_count++;
#endif
return self;
}
- (size_t)retainCount
{
assert(PRE_IVAR->retain_count >= 0);
return (size_t)PRE_IVAR->retain_count;
}
- (void)release
{
#if defined(OF_ATOMIC_OPS)
if (of_atomic_dec_32(&PRE_IVAR->retain_count) <= 0)
[self dealloc];
#elif defined(OF_THREADS)
size_t c;
assert(of_spinlock_lock(&PRE_IVAR->retain_spinlock));
c = --PRE_IVAR->retain_count;
assert(of_spinlock_unlock(&PRE_IVAR->retain_spinlock));
if (!c)
[self dealloc];
#else
if (--PRE_IVAR->retain_count <= 0)
[self dealloc];
#endif
}
- autorelease
{
/*
* Cache OFAutoreleasePool since class lookups are expensive with the
|
|
<
<
|
<
<
<
|
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
|
pointer: ptr];
}
- retain
{
#if defined(OF_ATOMIC_OPS)
of_atomic_inc_32(&PRE_IVAR->retain_count);
#else
assert(of_spinlock_lock(&PRE_IVAR->retain_spinlock));
PRE_IVAR->retain_count++;
assert(of_spinlock_unlock(&PRE_IVAR->retain_spinlock));
#endif
return self;
}
- (size_t)retainCount
{
assert(PRE_IVAR->retain_count >= 0);
return (size_t)PRE_IVAR->retain_count;
}
- (void)release
{
#if defined(OF_ATOMIC_OPS)
if (of_atomic_dec_32(&PRE_IVAR->retain_count) <= 0)
[self dealloc];
#else
size_t c;
assert(of_spinlock_lock(&PRE_IVAR->retain_spinlock));
c = --PRE_IVAR->retain_count;
assert(of_spinlock_unlock(&PRE_IVAR->retain_spinlock));
if (!c)
[self dealloc];
#endif
}
- autorelease
{
/*
* Cache OFAutoreleasePool since class lookups are expensive with the
|