47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
-
+
-
-
+
+
|
static uintptr_t count = 0;
static uintptr_t size = 0;
#endif
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OF_CONSTRUCTOR()
{
OFEnsure(OFTLSKeyNew(&objectsKey) == 0);
if (OFTLSKeyNew(&objectsKey) != 0 || OFTLSKeyNew(&countKey) != 0 ||
OFEnsure(OFTLSKeyNew(&countKey) == 0);
OFEnsure(OFTLSKeyNew(&sizeKey) == 0);
OFTLSKeyNew(&sizeKey) != 0)
OBJC_ERROR("Failed to create TLS keys!");
}
#endif
void *
objc_autoreleasePoolPush()
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
|
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
130
131
132
133
134
135
136
137
138
139
140
141
142
|
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
-
-
+
+
+
-
+
+
-
-
+
+
-
-
+
+
+
-
+
+
|
if (freeMem) {
free(objects);
objects = NULL;
#if defined(OF_HAVE_COMPILER_TLS) || !defined(OF_HAVE_THREADS)
size = 0;
#else
OFEnsure(OFTLSKeySet(objectsKey, objects) == 0);
OFEnsure(OFTLSKeySet(sizeKey, (void *)0) == 0);
if (OFTLSKeySet(objectsKey, objects) != 0 ||
OFTLSKeySet(sizeKey, (void *)0) != 0)
OBJC_ERROR("Failed to set TLS key!");
#endif
}
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(countKey, (void *)count) == 0);
if (OFTLSKeySet(countKey, (void *)count) != 0)
OBJC_ERROR("Failed to set TLS key!");
#endif
}
id
_objc_rootAutorelease(id object)
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
id *objects = OFTLSKeyGet(objectsKey);
uintptr_t count = (uintptr_t)OFTLSKeyGet(countKey);
uintptr_t size = (uintptr_t)OFTLSKeyGet(sizeKey);
#endif
if (count >= size) {
if (size == 0)
size = 16;
else
size *= 2;
OFEnsure((objects =
realloc(objects, size * sizeof(id))) != NULL);
if ((objects = realloc(objects, size * sizeof(id))) == NULL)
OBJC_ERROR("Failed to resize autorelease pool!");
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(objectsKey, objects) == 0);
OFEnsure(OFTLSKeySet(sizeKey, (void *)size) == 0);
if (OFTLSKeySet(objectsKey, objects) != 0 ||
OFTLSKeySet(sizeKey, (void *)size) != 0)
OBJC_ERROR("Failed to set TLS key!");
#endif
}
objects[count++] = object;
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
OFEnsure(OFTLSKeySet(countKey, (void *)count) == 0);
if (OFTLSKeySet(countKey, (void *)count) != 0)
OBJC_ERROR("Failed to set TLS key!");
#endif
return object;
}
|