ObjFW  Check-in [76ee8ab481]

Overview
Comment:OFThread: Support setting the name while running
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 76ee8ab48131265e39c39ae223bc985d5ecc697e18c51d598c284cd2ad7b7096
User & Date: js on 2017-10-07 14:57:14
Other Links: manifest | tags
Context
2017-10-07
15:12
OFThread: Fix setting the name on the wrong thread check-in: c211f691e7 user: js tags: trunk
14:57
OFThread: Support setting the name while running check-in: 76ee8ab481 user: js tags: trunk
11:22
OFThread: Fix the name accidentally being readonly check-in: 2f6a0e5ba9 user: js tags: trunk
Changes

Modified configure.ac from [8d9285e4df] to [f20413e5a9].

181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
	[OBJCFLAGS="$OBJCFLAGS -Wshorten-64-to-32"])
AX_CHECK_COMPILER_FLAGS([-Wundeclared-selector -Werror],
	[OBJCFLAGS="$OBJCFLAGS -Wundeclared-selector"])
AX_CHECK_COMPILER_FLAGS([-Wsemicolon-before-method-body -Werror],
	[OBJCFLAGS="$OBJCFLAGS -Wsemicolon-before-method-body"])
AX_CHECK_COMPILER_FLAGS([-Wobjc-missing-property-synthesis -Werror],
	[OBJCFLAGS="$OBJCFLAGS -Wobjc-missing-property-synthesis"])
AX_CHECK_COMPILER_FLAGS([-Watomic-properties -Werror], [
	OBJCFLAGS="$OBJCFLAGS -Watomic-properties"
	TESTS_OBJCFLAGS="$TESTS_OBJCFLAGS -Wno-atomic-properties"
])

AC_MSG_CHECKING(whether Objective C compiler supports properties)
AC_TRY_COMPILE([
	#ifdef __has_attribute
	# if __has_attribute(objc_root_class)
	__attribute__((__objc_root_class__))
	# endif







<
<
<
<







181
182
183
184
185
186
187




188
189
190
191
192
193
194
	[OBJCFLAGS="$OBJCFLAGS -Wshorten-64-to-32"])
AX_CHECK_COMPILER_FLAGS([-Wundeclared-selector -Werror],
	[OBJCFLAGS="$OBJCFLAGS -Wundeclared-selector"])
AX_CHECK_COMPILER_FLAGS([-Wsemicolon-before-method-body -Werror],
	[OBJCFLAGS="$OBJCFLAGS -Wsemicolon-before-method-body"])
AX_CHECK_COMPILER_FLAGS([-Wobjc-missing-property-synthesis -Werror],
	[OBJCFLAGS="$OBJCFLAGS -Wobjc-missing-property-synthesis"])





AC_MSG_CHECKING(whether Objective C compiler supports properties)
AC_TRY_COMPILE([
	#ifdef __has_attribute
	# if __has_attribute(objc_root_class)
	__attribute__((__objc_root_class__))
	# endif

Modified src/OFThread.h from [f66e3d5e03] to [2fd0087f7e].

75
76
77
78
79
80
81





82
83
84
85
86
87
88
89
90
	OFMutableDictionary *_threadDictionary;
@private
	OFString *_Nullable _name;
}

/*!
 * The name for the thread to use when starting it.





 */
@property OF_NULLABLE_PROPERTY (copy, nonatomic) OFString *name;

# ifdef OF_HAVE_BLOCKS
/*!
 * The block to execute in the thread.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    of_thread_block_t threadBlock;







>
>
>
>
>

|







75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
	OFMutableDictionary *_threadDictionary;
@private
	OFString *_Nullable _name;
}

/*!
 * The name for the thread to use when starting it.
 *
 * @note While this can be changed after the thread has been started, it will
 *	 have no effect once the thread started. If you want to change the name
 *	 of the current thread after it has been started, look at the class
 *	 method @ref setName:.
 */
@property OF_NULLABLE_PROPERTY (copy) OFString *name;

# ifdef OF_HAVE_BLOCKS
/*!
 * The block to execute in the thread.
 */
@property OF_NULLABLE_PROPERTY (readonly, nonatomic)
    of_thread_block_t threadBlock;
160
161
162
163
164
165
166

















167
168
169
170
171
172
173
/*!
 * @brief Terminates the current thread, letting it return the specified object.
 *
 * @param object The object which the terminated thread will return
 */
+ (void)terminateWithObject: (nullable id)object OF_NO_RETURN;


















# ifdef OF_HAVE_BLOCKS
/*!
 * @brief Initializes an already allocated thread with the specified block.
 *
 * @param threadBlock A block which is executed by the thread
 * @return An initialized OFThread.
 */







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







165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*!
 * @brief Terminates the current thread, letting it return the specified object.
 *
 * @param object The object which the terminated thread will return
 */
+ (void)terminateWithObject: (nullable id)object OF_NO_RETURN;

/*!
 * @brief Sets the name of the current thread.
 *
 * Unlike the instance method, this can be used after the thread has been
 * started.
 *
 * @param name The new name for the current thread.
 */
+ (void)setName: (nullable OFString *)name;

/*!
 * @brief Returns the name of the current thread.
 *
 * @return The name of the current thread.
 */
+ (nullable OFString *)name;

# ifdef OF_HAVE_BLOCKS
/*!
 * @brief Initializes an already allocated thread with the specified block.
 *
 * @param threadBlock A block which is executed by the thread
 * @return An initialized OFThread.
 */

Modified src/OFThread.m from [e635f40c39] to [2f9aa72b9d].

47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67

#ifdef OF_NINTENDO_3DS
# include <3ds/svc.h>
#endif

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

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

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

#ifdef OF_NINTENDO_DS
# define asm __asm__







|
|
|
|
|
>
|
|







47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#ifdef OF_NINTENDO_3DS
# include <3ds/svc.h>
#endif

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

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

#ifdef OF_NINTENDO_DS
# define asm __asm__
267
268
269
270
271
272
273
















274
275
276
277
278
279
280

	[OFAutoreleasePool of_handleThreadTermination];

	[thread release];

	of_thread_exit();
}

















+ (void)of_createMainThread
{
	mainThread = [[OFThread alloc] init];
	mainThread->_thread = of_thread_current();

	if (!of_tlskey_set(threadSelfKey, mainThread))







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







268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

	[OFAutoreleasePool of_handleThreadTermination];

	[thread release];

	of_thread_exit();
}

+ (void)setName: (OFString *)name
{
	[[OFThread currentThread] setName: name];

	if (name != nil)
		of_thread_set_name(
		    [name cStringWithEncoding: [OFLocalization encoding]]);
	else
		of_thread_set_name(class_getName([self class]));
}

+ (OFString *)name
{
	return [[OFThread currentThread] name];
}

+ (void)of_createMainThread
{
	mainThread = [[OFThread alloc] init];
	mainThread->_thread = of_thread_current();

	if (!of_tlskey_set(threadSelfKey, mainThread))
348
349
350
351
352
353
354
355

356
357
358
359
360
361
362

	if (!of_thread_new(&_thread, callMain, self, &_attr)) {
		[self release];
		@throw [OFThreadStartFailedException exceptionWithThread: self];
	}

	if (_name != nil)
		of_thread_set_name([_name UTF8String]);

	else
		of_thread_set_name(class_getName([self class]));
}

- (id)join
{
	if (_running == OF_THREAD_NOT_RUNNING || !of_thread_join(_thread))







|
>







365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380

	if (!of_thread_new(&_thread, callMain, self, &_attr)) {
		[self release];
		@throw [OFThreadStartFailedException exceptionWithThread: self];
	}

	if (_name != nil)
		of_thread_set_name(
		    [_name cStringWithEncoding: [OFLocalization encoding]]);
	else
		of_thread_set_name(class_getName([self class]));
}

- (id)join
{
	if (_running == OF_THREAD_NOT_RUNNING || !of_thread_join(_thread))