ObjFW  Check-in [f1637e9310]

Overview
Comment:Resolve more FIXMEs.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f1637e9310171519dee4852fe0996b42c81da4163070dce65c10cc4abcc546a9
User & Date: js on 2009-11-13 18:53:10
Other Links: manifest | tags
Context
2009-11-13
21:02
Fix one more FIXME. check-in: d7d45d4b69 user: js tags: trunk
18:53
Resolve more FIXMEs. check-in: f1637e9310 user: js tags: trunk
18:42
Add OFMutex(Lock|Unlock)FailedException and fix a few FIXMEs. check-in: 9a623a35d0 user: js tags: trunk
Changes

Modified src/OFExceptions.h from [dcad64c6f9] to [26a733beee].

678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697

/**
 * An OFException indicating that joining the thread failed.
 */
@interface OFThreadJoinFailedException: OFException {}
@end

/**
 * An OFException indicating that the thread has been canceled.
 */
@interface OFThreadCanceledException: OFException {}
@end

/**
 * An OFException indicating that locking a mutex failed.
 */
@interface OFMutexLockFailedException: OFException {}
@end

/**







<
<
<
<
<
<







678
679
680
681
682
683
684






685
686
687
688
689
690
691

/**
 * An OFException indicating that joining the thread failed.
 */
@interface OFThreadJoinFailedException: OFException {}
@end







/**
 * An OFException indicating that locking a mutex failed.
 */
@interface OFMutexLockFailedException: OFException {}
@end

/**

Modified src/OFExceptions.m from [5a256fa7d9] to [f159950386].

977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
	if (string != nil)
		return string;

	string = [[OFString alloc] initWithFormat:
	    @"Joining a thread of class %s failed! Most likely, another thread "
	    @"already waits for the thread to join.", [class_ className]];

	return string;
}
@end

/* FIXME: Not needed anymore? */
@implementation OFThreadCanceledException
- (OFString*)string
{
	if (string != nil)
		return string;

	string = [[OFString alloc] initWithFormat:
	    @"The requested action cannot be performed because the thread of "
	    @"class %s was canceled!", [class_ className]];

	return string;
}
@end

@implementation OFMutexLockFailedException
- (OFString*)string
{







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







977
978
979
980
981
982
983















984
985
986
987
988
989
990
	if (string != nil)
		return string;

	string = [[OFString alloc] initWithFormat:
	    @"Joining a thread of class %s failed! Most likely, another thread "
	    @"already waits for the thread to join.", [class_ className]];
















	return string;
}
@end

@implementation OFMutexLockFailedException
- (OFString*)string
{

Modified src/OFThread.m from [40c1edc042] to [18efd35d69].

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145




146

147
148
149
150
151
152
153
	return self;
}

- initWithDestructor: (void(*)(id))destructor
{
	self = [super init];

	/* FIXME: Call destructor on Win32 */
	if (!of_tlskey_new(&key, destructor)) {
		Class c = isa;
		[super dealloc];
		@throw [OFInitializationFailedException newWithClass: c];
	}

	return self;
}





/* FIXME: Add dealloc! */

@end

@implementation OFMutex
+ mutex
{
	return [[[self alloc] init] autorelease];
}







<









>
>
>
>
|
>







129
130
131
132
133
134
135

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
	return self;
}

- initWithDestructor: (void(*)(id))destructor
{
	self = [super init];


	if (!of_tlskey_new(&key, destructor)) {
		Class c = isa;
		[super dealloc];
		@throw [OFInitializationFailedException newWithClass: c];
	}

	return self;
}

- (void)dealloc
{
	of_tlskey_free(key);

	[super dealloc];
}
@end

@implementation OFMutex
+ mutex
{
	return [[[self alloc] init] autorelease];
}

Modified src/threading.h from [7b407a5ba1] to [44dc680850].

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
{
#ifndef _WIN32
	void *ret;

	if (pthread_join(thread, &ret))
		return NO;

	/* FIXME: Do we need a way to differentiate? */
	return (ret != PTHREAD_CANCELED ? YES : NO);
#else
	if (WaitForSingleObject(thread, INFINITE))
		return NO;

	CloseHandle(thread);








<







50
51
52
53
54
55
56

57
58
59
60
61
62
63
{
#ifndef _WIN32
	void *ret;

	if (pthread_join(thread, &ret))
		return NO;


	return (ret != PTHREAD_CANCELED ? YES : NO);
#else
	if (WaitForSingleObject(thread, INFINITE))
		return NO;

	CloseHandle(thread);

159
160
161
162
163
164
165











#ifndef _WIN32
	return (pthread_setspecific(key, p) ? NO : YES);
#else
	return (TlsSetValue(key, p) ? YES : NO);
#endif
}

















>
>
>
>
>
>
>
>
>
>
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

#ifndef _WIN32
	return (pthread_setspecific(key, p) ? NO : YES);
#else
	return (TlsSetValue(key, p) ? YES : NO);
#endif
}

static OF_INLINE BOOL
of_tlskey_free(of_tlskey_t key)
{
#ifndef _WIN32
	return (pthread_key_delete(key) ? NO : YES);
#else
	return (TlsFree(key) ? YES : NO);
#endif
}