ObjFW  Check-in [4ad6599390]

Overview
Comment:Cache 32 autorelease pools per thread.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 4ad65993900129ea5f9a9962183826dbd0d0c9e10e71ea311a4a1209ea233e39
User & Date: js on 2012-08-09 15:37:08
Other Links: manifest | tags
Context
2012-08-10
20:08
Directly use the runtime's autorelease pools. check-in: 1255f3a11a user: js tags: trunk
2012-08-09
15:37
Cache 32 autorelease pools per thread. check-in: 4ad6599390 user: js tags: trunk
2012-08-07
08:36
Move objc_autorelease() to arc.m. check-in: 19f4701ed3 user: js tags: trunk
Changes

Modified src/OFAutoreleasePool.m from [d255c7767f] to [1a29185e97].

28
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
# import "threading.h"

# import "OFInitializationFailedException.h"
#endif

#import "autorelease.h"



#ifdef OF_COMPILER_TLS
static __thread void *first = NULL;

#else
static of_tlskey_t firstKey;
#endif

@implementation OFAutoreleasePool
#ifndef OF_COMPILER_TLS
+ (void)initialize
{
	if (self != [OFAutoreleasePool class])
		return;

	if (!of_tlskey_new(&firstKey))
		@throw [OFInitializationFailedException
		    exceptionWithClass: self];
}
#endif






















+ (id)addObject: (id)object
{
#ifndef OF_COMPILER_TLS
	void *first = of_tlskey_get(firstKey);
#endif








>
>


>

|









|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







28
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
# import "threading.h"

# import "OFInitializationFailedException.h"
#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

@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
{
#ifndef OF_COMPILER_TLS
	OFAutoreleasePool **cache = of_tlskey_get(cacheKey);
#endif

	if (cache != NULL) {
		unsigned i;

		for (i = 0; i < MAX_CACHE_SIZE; i++) {
			if (cache[i] != NULL) {
				OFAutoreleasePool *pool = cache[i];
				cache[i] = NULL;
				return pool;
			}
		}
	}

	return [super alloc];
}

+ (id)addObject: (id)object
{
#ifndef OF_COMPILER_TLS
	void *first = of_tlskey_get(firstKey);
#endif

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
- (void)drain
{
	[self dealloc];
}

- (void)dealloc
{




	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);



























	[super dealloc];
}

- retain
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]







>
>
>
>














>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
- (void)drain
{
	[self dealloc];
}

- (void)dealloc
{
#ifndef OF_COMPILER_TLS
	OFAutoreleasePool **cache = of_tlskey_get(cacheKey);
#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)) {
			free(cache);
			cache = NULL;
		}
#endif
	}

	if (cache != NULL) {
		unsigned i;

		for (i = 0; i < MAX_CACHE_SIZE; i++) {
			if (cache[i] == NULL) {
				pool = NULL;
				ignoreRelease = NO;

				cache[i] = self;

				return;
			}
		}
	}

	[super dealloc];
}

- retain
{
	@throw [OFNotImplementedException exceptionWithClass: [self class]