ObjFW  Check-in [ddcee670e4]

Overview
Comment:Optimize OFMutex on Win32 and add missing -[dealloc].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: ddcee670e4f6edf00cf2953719d71aba156afe75b1a3516da046f0631555e36a
User & Date: js on 2009-06-01 04:08:43
Other Links: manifest | tags
Context
2009-06-01
12:02
Write a warning to stderr if objc_sync_{enter,exit} fails. check-in: 216caca8a0 user: js tags: trunk
04:08
Optimize OFMutex on Win32 and add missing -[dealloc]. check-in: ddcee670e4 user: js tags: trunk
04:02
Fix and optimize @synchronize on Win32. check-in: 362a943099 user: js tags: trunk
Changes

Modified src/OFThread.h from [0d2fba1b4a] to [48c9aa376a].

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
 * A class for creating mutual exclusions.
 */
@interface OFMutex: OFObject
{
#ifndef _WIN32
	pthread_mutex_t mutex;
#else
	HANDLE mutex;
#endif
}

/**
 * \return A new, autoreleased mutex.
 */
+ mutex;







|







116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
 * A class for creating mutual exclusions.
 */
@interface OFMutex: OFObject
{
#ifndef _WIN32
	pthread_mutex_t mutex;
#else
	CRITICAL_SECTION mutex;
#endif
}

/**
 * \return A new, autoreleased mutex.
 */
+ mutex;

Modified src/OFThread.m from [e77c0b551d] to [a7103d64e5].

183
184
185
186
187
188
189
190
191
192
193
194
195
196



197
198
199
200
201
202
203
204

205
206
207
208
209
210
211
212
213
214
215
216

217
218
219
220
221
222
223












224

- init
{
	self = [super init];

#ifndef _WIN32
	if (pthread_mutex_init(&mutex, NULL)) {
#else
	if ((mutex = CreateMutex(NULL, FALSE, NULL)) == NULL) {
#endif
		Class c = isa;
		[self dealloc];
		@throw [OFInitializationFailedException newWithClass: c];
	}




	return self;
}

- lock
{
	/* FIXME: Add error-handling */
#ifndef _WIN32

	pthread_mutex_lock(&mutex);
#else
	WaitForSingleObject(mutex, INFINITE);
#endif

	return self;
}

- unlock
{
	/* FIXME: Add error-handling */
#ifndef _WIN32

	pthread_mutex_unlock(&mutex);
#else
	ReleaseMutex(mutex);
#endif

	return self;
}












@end







<
<
<




>
>
>






<

>


|







<

>


|




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

183
184
185
186
187
188
189



190
191
192
193
194
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
210
211
212
213
214

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236

- init
{
	self = [super init];

#ifndef _WIN32
	if (pthread_mutex_init(&mutex, NULL)) {



		Class c = isa;
		[self dealloc];
		@throw [OFInitializationFailedException newWithClass: c];
	}
#else
	InitializeCriticalSection(&mutex);
#endif

	return self;
}

- lock
{

#ifndef _WIN32
	/* FIXME: Add error-handling */
	pthread_mutex_lock(&mutex);
#else
	EnterCriticalSection(&mutex);
#endif

	return self;
}

- unlock
{

#ifndef _WIN32
	/* FIXME: Add error-handling */
	pthread_mutex_unlock(&mutex);
#else
	LeaveCriticalSection(&mutex);
#endif

	return self;
}

- (void)dealloc
{
#ifndef _WIN32
	/* FIXME: Add error-handling */
	pthread_mutex_destroy(&mutex);
#else
	DeleteCriticalSection(&mutex);
#endif

	[super dealloc];
}
@end