18
19
20
21
22
23
24
25
26
27
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
|
18
19
20
21
22
23
24
25
26
27
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
|
-
+
-
+
-
+
-
+
-
+
|
#include <stdlib.h>
#import "OFAutoreleasePool.h"
#import "OFArray.h"
#import "macros.h"
#if !defined(OF_COMPILER_TLS) && defined(OF_THREADS)
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
# import "threading.h"
# import "OFInitializationFailedException.h"
#endif
#import "autorelease.h"
#define MAX_CACHE_SIZE 0x20
#if defined(OF_COMPILER_TLS)
#if defined(OF_HAVE_COMPILER_TLS)
static __thread OFAutoreleasePool **cache = NULL;
#elif defined(OF_THREADS)
#elif defined(OF_HAVE_THREADS)
static of_tlskey_t cacheKey;
#else
static OFAutoreleasePool **cache = NULL;
#endif
@implementation OFAutoreleasePool
#if !defined(OF_COMPILER_TLS) && defined(OF_THREADS)
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
+ (void)initialize
{
if (self != [OFAutoreleasePool class])
return;
if (!of_tlskey_new(&cacheKey))
@throw [OFInitializationFailedException
exceptionWithClass: self];
}
#endif
+ alloc
{
#if !defined(OF_COMPILER_TLS) && defined(OF_THREADS)
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFAutoreleasePool **cache = of_tlskey_get(cacheKey);
#endif
if (cache != NULL) {
unsigned i;
for (i = 0; i < MAX_CACHE_SIZE; i++) {
|
115
116
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
|
115
116
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
|
-
+
-
+
|
- (void)drain
{
[self dealloc];
}
- (void)dealloc
{
#if !defined(OF_COMPILER_TLS) && defined(OF_THREADS)
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFAutoreleasePool **cache = of_tlskey_get(cacheKey);
#endif
if (ignoreRelease)
return;
ignoreRelease = YES;
objc_autoreleasePoolPop(pool);
if (cache == NULL) {
cache = calloc(sizeof(OFAutoreleasePool*), MAX_CACHE_SIZE);
#if !defined(OF_COMPILER_TLS) && defined(OF_THREADS)
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
if (!of_tlskey_set(cacheKey, cache)) {
free(cache);
cache = NULL;
}
#endif
}
|