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
|
#endif
#import "autorelease.h"
#define MAX_CACHE_SIZE 0x20
#ifdef OF_COMPILER_TLS
static __thread void *first = NULL;
static __thread OFAutoreleasePool **cache = NULL;
#else
static of_tlskey_t firstKey, cacheKey;
#endif
id
of_autorelease(id object)
{
#ifndef OF_COMPILER_TLS
void *first = of_tlskey_get(firstKey);
#endif
if (first == NULL)
[[OFAutoreleasePool alloc] init];
return _objc_rootAutorelease(object);
}
@implementation OFAutoreleasePool
#ifndef OF_COMPILER_TLS
+ (void)initialize
{
if (self != [OFAutoreleasePool class])
return;
if (!of_tlskey_new(&firstKey) || !of_tlskey_new(&cacheKey))
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
#endif
+ alloc
{
|
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
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
|
#endif
#import "autorelease.h"
#define MAX_CACHE_SIZE 0x20
#ifdef OF_COMPILER_TLS
static __thread OFAutoreleasePool **cache = NULL;
#else
static of_tlskey_t cacheKey;
#endif
@implementation OFAutoreleasePool
#ifndef OF_COMPILER_TLS
+ (void)initialize
{
if (self != [OFAutoreleasePool class])
return;
if (!of_tlskey_new(&cacheKey))
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
#endif
+ alloc
{
|
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
}
return [super alloc];
}
+ (id)addObject: (id)object
{
return of_autorelease(object);
}
+ (void)OF_releaseAll
{
#ifndef OF_COMPILER_TLS
void *first = of_tlskey_get(firstKey);
#endif
objc_autoreleasePoolPop(first);
}
- init
{
self = [super init];
@try {
#ifndef OF_COMPILER_TLS
void *first = of_tlskey_get(firstKey);
#endif
pool = objc_autoreleasePoolPush();
if (first == NULL)
#ifdef OF_COMPILER_TLS
first = pool;
#else
OF_ENSURE(of_tlskey_set(firstKey, pool));
#endif
_objc_rootAutorelease(self);
} @catch (id e) {
[self release];
@throw e;
}
return self;
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
}
return [super alloc];
}
+ (id)addObject: (id)object
{
return _objc_rootAutorelease(object);
}
- init
{
self = [super init];
@try {
pool = objc_autoreleasePoolPush();
_objc_rootAutorelease(self);
} @catch (id e) {
[self release];
@throw e;
}
return self;
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
#endif
if (ignoreRelease)
return;
ignoreRelease = YES;
#ifdef OF_COMPILER_TLS
if (first == pool)
first = NULL;
#else
if (of_tlskey_get(firstKey) == pool)
OF_ENSURE(of_tlskey_set(firstKey, NULL));
#endif
objc_autoreleasePoolPop(pool);
if (cache == NULL) {
cache = calloc(sizeof(OFAutoreleasePool*), MAX_CACHE_SIZE);
#ifndef OF_COMPILER_TLS
if (!of_tlskey_set(cacheKey, cache)) {
|
<
<
<
<
<
<
<
<
|
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#endif
if (ignoreRelease)
return;
ignoreRelease = YES;
objc_autoreleasePoolPop(pool);
if (cache == NULL) {
cache = calloc(sizeof(OFAutoreleasePool*), MAX_CACHE_SIZE);
#ifndef OF_COMPILER_TLS
if (!of_tlskey_set(cacheKey, cache)) {
|