ObjFW  Check-in [29e4d00225]

Overview
Comment:OFAutoreleasePool: Free pool cache on thread exit.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 29e4d0022505f1823a6894384bb4fa1989fc0bab998ab57c5a4336456223dd39
User & Date: js on 2013-09-15 18:51:51
Other Links: manifest | tags
Context
2013-09-15
21:22
Fix a few format string length modifiers. check-in: 65d5a8f675 user: js tags: trunk
18:51
OFAutoreleasePool: Free pool cache on thread exit. check-in: 29e4d00225 user: js tags: trunk
2013-08-25
21:16
Add -[OFString pathExtension]. check-in: 37dc5d933f user: js tags: trunk
Changes

Modified ObjFW.xcodeproj/project.pbxproj from [a70a46e1af] to [d70e27f8a7].

43
44
45
46
47
48
49

50
51
52
53
54
55
56
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57







+







		4B067FC0177BA6F900B8CFDA /* OFChangePermissionsFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B067FB4177BA6F900B8CFDA /* OFChangePermissionsFailedException.m */; };
		4B067FC1177BA6F900B8CFDA /* OFCreateSymbolicLinkFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B067FB5177BA6F900B8CFDA /* OFCreateSymbolicLinkFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B067FC2177BA6F900B8CFDA /* OFCreateSymbolicLinkFailedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B067FB6177BA6F900B8CFDA /* OFCreateSymbolicLinkFailedException.m */; };
		4B11005C14329B9A003A45D8 /* OFXMLNode.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B11005A14329B9A003A45D8 /* OFXMLNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B11005D14329B9A003A45D8 /* OFXMLNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B11005B14329B9A003A45D8 /* OFXMLNode.m */; };
		4B141BA415FCDF74000C21A8 /* OFSortedList.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B141BA215FCDF74000C21A8 /* OFSortedList.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B141BA515FCDF74000C21A8 /* OFSortedList.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B141BA315FCDF74000C21A8 /* OFSortedList.m */; };
		4B1473CB17E6391900B46BB8 /* OFAutoreleasePool+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B1473CA17E6391900B46BB8 /* OFAutoreleasePool+Private.h */; };
		4B17FF73133A2A76003E6DCD /* OFException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B17FF71133A28FC003E6DCD /* OFException.m */; };
		4B17FF74133A2AAB003E6DCD /* OFException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF70133A28FC003E6DCD /* OFException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B17FF77133A2B18003E6DCD /* OFNotImplementedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B17FF78133A2B18003E6DCD /* OFNotImplementedException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B17FF76133A2B18003E6DCD /* OFNotImplementedException.m */; };
		4B17FF7B133A2C15003E6DCD /* OFOutOfRangeException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF79133A2C14003E6DCD /* OFOutOfRangeException.h */; settings = {ATTRIBUTES = (Public, ); }; };
		4B17FF7C133A2C15003E6DCD /* OFOutOfRangeException.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B17FF7A133A2C15003E6DCD /* OFOutOfRangeException.m */; };
		4B17FF7F133A2D17003E6DCD /* OFAllocFailedException.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B17FF7D133A2D16003E6DCD /* OFAllocFailedException.h */; settings = {ATTRIBUTES = (Public, ); }; };
485
486
487
488
489
490
491

492
493
494
495
496
497
498
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500







+







		4B067FB6177BA6F900B8CFDA /* OFCreateSymbolicLinkFailedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFCreateSymbolicLinkFailedException.m; path = src/exceptions/OFCreateSymbolicLinkFailedException.m; sourceTree = "<group>"; };
		4B0D249411DFAA3D00ED6FFC /* OFXMLElementBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLElementBuilder.h; path = src/OFXMLElementBuilder.h; sourceTree = "<group>"; };
		4B0D249511DFAA3D00ED6FFC /* OFXMLElementBuilder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLElementBuilder.m; path = src/OFXMLElementBuilder.m; sourceTree = "<group>"; };
		4B11005A14329B9A003A45D8 /* OFXMLNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFXMLNode.h; path = src/OFXMLNode.h; sourceTree = "<group>"; };
		4B11005B14329B9A003A45D8 /* OFXMLNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFXMLNode.m; path = src/OFXMLNode.m; sourceTree = "<group>"; };
		4B141BA215FCDF74000C21A8 /* OFSortedList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFSortedList.h; path = src/OFSortedList.h; sourceTree = "<group>"; };
		4B141BA315FCDF74000C21A8 /* OFSortedList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFSortedList.m; path = src/OFSortedList.m; sourceTree = "<group>"; };
		4B1473CA17E6391900B46BB8 /* OFAutoreleasePool+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "OFAutoreleasePool+Private.h"; path = "src/OFAutoreleasePool+Private.h"; sourceTree = "<group>"; };
		4B175C1D116D130B003C99CB /* OFApplication.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFApplication.h; path = src/OFApplication.h; sourceTree = "<group>"; };
		4B175C1E116D130B003C99CB /* OFApplication.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFApplication.m; path = src/OFApplication.m; sourceTree = "<group>"; };
		4B17FF70133A28FC003E6DCD /* OFException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFException.h; path = src/exceptions/OFException.h; sourceTree = "<group>"; };
		4B17FF71133A28FC003E6DCD /* OFException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFException.m; path = src/exceptions/OFException.m; sourceTree = "<group>"; };
		4B17FF75133A2B18003E6DCD /* OFNotImplementedException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFNotImplementedException.h; path = src/exceptions/OFNotImplementedException.h; sourceTree = "<group>"; };
		4B17FF76133A2B18003E6DCD /* OFNotImplementedException.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OFNotImplementedException.m; path = src/exceptions/OFNotImplementedException.m; sourceTree = "<group>"; };
		4B17FF79133A2C14003E6DCD /* OFOutOfRangeException.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OFOutOfRangeException.h; path = src/exceptions/OFOutOfRangeException.h; sourceTree = "<group>"; };
1109
1110
1111
1112
1113
1114
1115

1116
1117
1118
1119
1120
1121
1122
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125







+







				4B2B3E74140D430500EC2F7C /* OFArray_adjacent.m */,
				4B9BB7B9141CDE2D000AD1CC /* OFArray_adjacentSubarray.h */,
				4B9BB7BA141CDE2D000AD1CC /* OFArray_adjacentSubarray.m */,
				4B9BB7BB141CDE2D000AD1CC /* OFArray_subarray.h */,
				4B9BB7BC141CDE2D000AD1CC /* OFArray_subarray.m */,
				4B67995C1099E7C50041064A /* OFAutoreleasePool.h */,
				4B67995D1099E7C50041064A /* OFAutoreleasePool.m */,
				4B1473CA17E6391900B46BB8 /* OFAutoreleasePool+Private.h */,
				4BD86D801237A6C600ED9912 /* OFBlock.h */,
				4BD86D811237A6C600ED9912 /* OFBlock.m */,
				4BAF5F46123460C900F4E111 /* OFCollection.h */,
				4B6743F7163C395900EB1E59 /* OFCondition.h */,
				4B6743F8163C395900EB1E59 /* OFCondition.m */,
				4BE5F0D712DF4225005C7A0C /* OFConstantString.h */,
				4BE5F0D812DF4225005C7A0C /* OFConstantString.m */,
1564
1565
1566
1567
1568
1569
1570

1571
1572
1573
1574
1575
1576
1577
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581







+







				4B6743F5163C384A00EB1E59 /* OFUnlockFailedException.h in Headers */,
				4B17FFB1133A3664003E6DCD /* OFUnsupportedProtocolException.h in Headers */,
				4BA4846215CC9F1E00D75360 /* OFUnsupportedVersionException.h in Headers */,
				4B55A116133AC24600B58A93 /* OFWriteFailedException.h in Headers */,
				4B55A109133AC05100B58A93 /* common.h in Headers */,
				4B2B3E7D140D430500EC2F7C /* OFArray_adjacent.h in Headers */,
				4B9BB7BD141CDE2D000AD1CC /* OFArray_adjacentSubarray.h in Headers */,
				4B1473CB17E6391900B46BB8 /* OFAutoreleasePool+Private.h in Headers */,
				4BA85BCA140ECCE800E91D51 /* OFCountedSet_hashtable.h in Headers */,
				4B2B3E7F140D430500EC2F7C /* OFDictionary_hashtable.h in Headers */,
				4B2B3E81140D430500EC2F7C /* OFMutableArray_adjacent.h in Headers */,
				4B2B3E83140D430500EC2F7C /* OFMutableDictionary_hashtable.h in Headers */,
				4BA85BCC140ECCE800E91D51 /* OFMutableSet_hashtable.h in Headers */,
				4B552552147AA5DB0003BF47 /* OFMutableString_UTF8.h in Headers */,
				4B6C8AD817BD5C2E00B194F2 /* OFRunLoop+Private.h in Headers */,

Added src/OFAutoreleasePool+Private.h version [814524f45d].

























1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * All rights reserved.
 *
 * This file is part of ObjFW. It may be distributed under the terms of the
 * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFAutoreleasePool.h"

#import "macros.h"

@interface OFAutoreleasePool (OF_PRIVATE_CATEGORY)
+ (void)OF_handleThreadTermination;
- (void)OF_super_dealloc;
@end

Modified src/OFAutoreleasePool.m from [06405e2bb2] to [c1b6db103b].

15
16
17
18
19
20
21

22
23
24
25
26
27
28
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29







+







 */

#include "config.h"

#include <stdlib.h>

#import "OFAutoreleasePool.h"
#import "OFAutoreleasePool+Private.h"

#import "macros.h"
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
# import "threading.h"

# import "OFInitializationFailedException.h"
#endif
73
74
75
76
77
78
79
















80
81
82
83
84
85
86
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







	return [super alloc];
}

+ (id)addObject: (id)object
{
	return _objc_rootAutorelease(object);
}

+ (void)OF_handleThreadTermination
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	OFAutoreleasePool **cache = of_tlskey_get(cacheKey);
#endif
	size_t i;

	if (cache != NULL) {
		for (i = 0; i < MAX_CACHE_SIZE; i++)
			[cache[i] OF_super_dealloc];

		free(cache);
		cache = NULL;
	}
}

- init
{
	self = [super init];

	@try {
		_pool = objc_autoreleasePoolPush();
111
112
113
114
115
116
117





118
119
120
121
122
123
124
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146







+
+
+
+
+







	[self dealloc];
}

- (void)drain
{
	[self dealloc];
}

- (void)OF_super_dealloc
{
	[super dealloc];
}

- (void)dealloc
{
#if !defined(OF_HAVE_COMPILER_TLS) && defined(OF_HAVE_THREADS)
	OFAutoreleasePool **cache = of_tlskey_get(cacheKey);
#endif

Modified src/OFString.m from [08f92f7b9f] to [afe2a7a5d7].

2165
2166
2167
2168
2169
2170
2171
2172

2173
2174
2175
2176
2177
2178
2179
2165
2166
2167
2168
2169
2170
2171

2172
2173
2174
2175
2176
2177
2178
2179







-
+







	return OF_PATH_CURRENT_DIRECTORY;
}

- (OFString*)stringByDeletingPathExtension
{
	void *pool;
	OFMutableArray *components;
	OFString *fileName, *ret;
	OFString *ret, *fileName;
	size_t pos;

	if ([self length] == 0)
		return [[self copy] autorelease];

	pool = objc_autoreleasePoolPush();
	components = [[[self pathComponents] mutableCopy] autorelease];

Modified src/OFThread.h from [79574f891b] to [9a4feafde7].

57
58
59
60
61
62
63

64
65
66
67
68
69
70
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71







+







# endif
	of_thread_t _thread;
	enum {
		OF_THREAD_NOT_RUNNING,
		OF_THREAD_RUNNING,
		OF_THREAD_WAITING_FOR_JOIN
	} _running;
	void *_pool;
# ifdef OF_HAVE_BLOCKS
	of_thread_block_t _threadBlock;
# endif
	id _returnValue;
	OFRunLoop *_runLoop;
	OFString *_name;
	OFMutableDictionary *_threadDictionary;

Modified src/OFThread.m from [a7b179a03a] to [6544d29ad9].

40
41
42
43
44
45
46

47
48
49
50
51
52
53
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54







+







#import "OFThread.h"
#import "OFThread+Private.h"
#import "OFRunLoop.h"
#import "OFList.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"
#import "OFAutoreleasePool+Private.h"

#ifdef _WIN32
# include <windows.h>
#endif

#import "OFInitializationFailedException.h"
#import "OFInvalidArgumentException.h"
75
76
77
78
79
80
81
82

83
84
85
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
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99







100

101
102
103
104
105
106
107
108







-
+
















-
-
-
-
-
-
-
+
-
+







{
	OFThread *thread = (OFThread*)object;

	if (!of_tlskey_set(threadSelfKey, thread))
		@throw [OFInitializationFailedException
		    exceptionWithClass: [thread class]];

	objc_autoreleasePoolPush();
	thread->_pool = objc_autoreleasePoolPush();

	/*
	 * Nasty workaround for thread implementations which can't return a
	 * value on join.
	 */
# ifdef OF_HAVE_BLOCKS
	if (thread->_threadBlock != NULL)
		thread->_returnValue = [thread->_threadBlock() retain];
	else
# endif
		thread->_returnValue = [[thread main] retain];

	[thread handleTermination];

	thread->_running = OF_THREAD_WAITING_FOR_JOIN;

# ifdef OF_OBJFW_RUNTIME
	/*
	 * As the values returned by objc_autoreleasePoolPush() in the ObjFW
	 * runtime are not actually pointers, but sequential numbers, 0 means
	 * we pop everything.
	 */
	objc_autoreleasePoolPop(0);
	objc_autoreleasePoolPop(thread->_pool);
# endif
	[OFAutoreleasePool OF_handleThreadTermination];

	[thread release];

	return 0;
}

static void
231
232
233
234
235
236
237
238
239
240
241
242
243
244

245

246
247
248
249
250
251
252
226
227
228
229
230
231
232







233

234
235
236
237
238
239
240
241







-
-
-
-
-
-
-
+
-
+







		thread->_returnValue = [object retain];

		[thread handleTermination];

		thread->_running = OF_THREAD_WAITING_FOR_JOIN;
	}

# ifdef OF_OBJFW_RUNTIME
	/*
	 * As the values returned by objc_autoreleasePoolPush() in the ObjFW
	 * runtime are not actually pointers, but sequential numbers, 0 means
	 * we pop everything.
	 */
	objc_autoreleasePoolPop(0);
	objc_autoreleasePoolPop(thread->_pool);
# endif
	[OFAutoreleasePool OF_handleThreadTermination];

	[thread release];

	of_thread_exit();
}

+ (void)OF_createMainThread