ObjFW  Check-in [2c78c6570b]

Overview
Comment:Add of_thread_set_name()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 2c78c6570bfbc9e0068dce77b4268b1db9d5a47b0d461ccf7a54b617efbb04fd
User & Date: js on 2014-07-19 16:16:13
Other Links: manifest | tags
Context
2014-07-19
16:16
Fix MinGW32 build check-in: 083e05b444 user: js tags: trunk
16:16
Add of_thread_set_name() check-in: 2c78c6570b user: js tags: trunk
10:47
Split threading.m into per-platform files check-in: 8abe07a0a3 user: js tags: trunk
Changes

Modified src/OFThread.h from [bd27888ffe] to [dbfdd8a5a4].

65
66
67
68
69
70
71
72
73


74
75
76
77
78
79
80
	} _running;
	void *_pool;
# ifdef OF_HAVE_BLOCKS
	of_thread_block_t _threadBlock;
# endif
	id _returnValue;
	OFRunLoop *_runLoop;
	OFString *_name;
	OFMutableDictionary *_threadDictionary;


}

# ifdef OF_HAVE_PROPERTIES
#  ifdef OF_HAVE_BLOCKS
@property (copy) of_thread_block_t threadBlock;
#  endif
@property (copy) OFString *name;







<

>
>







65
66
67
68
69
70
71

72
73
74
75
76
77
78
79
80
81
	} _running;
	void *_pool;
# ifdef OF_HAVE_BLOCKS
	of_thread_block_t _threadBlock;
# endif
	id _returnValue;
	OFRunLoop *_runLoop;

	OFMutableDictionary *_threadDictionary;
@private
	OFString *_name;
}

# ifdef OF_HAVE_PROPERTIES
#  ifdef OF_HAVE_BLOCKS
@property (copy) of_thread_block_t threadBlock;
#  endif
@property (copy) OFString *name;

Modified src/OFThread.m from [4615b52a3c] to [8e23861680].

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# include <unistd.h>
#endif

#ifdef OF_HAVE_SCHED_YIELD
# include <sched.h>
#endif

#if defined(OF_HAVE_THREADS) && defined(__HAIKU__)
# include <kernel/OS.h>
#endif

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







<
<
<
<







32
33
34
35
36
37
38




39
40
41
42
43
44
45
# include <unistd.h>
#endif

#ifdef OF_HAVE_SCHED_YIELD
# include <sched.h>
#endif





#import "OFThread.h"
#import "OFThread+Private.h"
#import "OFRunLoop.h"
#import "OFList.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFAutoreleasePool.h"
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
	objc_autoreleasePoolPop(thread->_pool);
	[OFAutoreleasePool OF_handleThreadTermination];

	[thread release];

	return 0;
}

static void
setThreadName(OFThread *thread)
{
# ifdef __HAIKU__
	OFString *name = thread->_name;

	if (name == nil)
		name = [thread className];

	rename_thread(get_pthread_thread_id(thread->_thread),
	    [name UTF8String]);
# endif
}
#endif

@implementation OFThread
#ifdef OF_HAVE_THREADS
# if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@synthesize threadBlock = _threadBlock;
# endif







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







109
110
111
112
113
114
115














116
117
118
119
120
121
122
	objc_autoreleasePoolPop(thread->_pool);
	[OFAutoreleasePool OF_handleThreadTermination];

	[thread release];

	return 0;
}














#endif

@implementation OFThread
#ifdef OF_HAVE_THREADS
# if defined(OF_HAVE_PROPERTIES) && defined(OF_HAVE_BLOCKS)
@synthesize threadBlock = _threadBlock;
# endif
327
328
329
330
331
332
333
334



335
336
337
338
339
340
341
	_running = OF_THREAD_RUNNING;

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

	setThreadName(self);



}

- (id)join
{
	if (_running == OF_THREAD_NOT_RUNNING || !of_thread_join(_thread))
		@throw [OFThreadJoinFailedException exceptionWithThread: self];








|
>
>
>







309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
	_running = OF_THREAD_RUNNING;

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

	if (_name != nil)
		of_thread_set_name(_thread, [_name UTF8String]);
	else
		of_thread_set_name(_thread, class_getName([self class]));
}

- (id)join
{
	if (_running == OF_THREAD_NOT_RUNNING || !of_thread_join(_thread))
		@throw [OFThreadJoinFailedException exceptionWithThread: self];

373
374
375
376
377
378
379
380



381


382
383
384
385
386
387
388
	OF_GETTER(_name, true)
}

- (void)setName: (OFString*)name
{
	OF_SETTER(_name, name, true, 1)

	if (_running == OF_THREAD_RUNNING)



		setThreadName(self);


}

- (void)dealloc
{
	if (_running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException
		    exceptionWithThread: self];







|
>
>
>
|
>
>







358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
	OF_GETTER(_name, true)
}

- (void)setName: (OFString*)name
{
	OF_SETTER(_name, name, true, 1)

	if (_running == OF_THREAD_RUNNING) {
		if (_name != nil)
			of_thread_set_name(_thread, [_name UTF8String]);
		else
			of_thread_set_name(_thread,
			    class_getName([self class]));
	}
}

- (void)dealloc
{
	if (_running == OF_THREAD_RUNNING)
		@throw [OFThreadStillRunningException
		    exceptionWithThread: self];

Modified src/threading.h from [e7a7a55554] to [ca3714aa7c].

83
84
85
86
87
88
89

90
91
92
93
94
95
96
# define of_thread_current GetCurrentThread
#else
# error of_thread_is_current not implemented!
# error of_thread_current not implemented!
#endif

extern bool of_thread_new(of_thread_t *thread, id (*function)(id), id data);

extern bool of_thread_join(of_thread_t thread);
extern bool of_thread_detach(of_thread_t thread);
extern void OF_NO_RETURN of_thread_exit(void);
extern void of_once(of_once_t *control, void (*func)(void));
extern bool of_mutex_new(of_mutex_t *mutex);
extern bool of_mutex_lock(of_mutex_t *mutex);
extern bool of_mutex_trylock(of_mutex_t *mutex);







>







83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# define of_thread_current GetCurrentThread
#else
# error of_thread_is_current not implemented!
# error of_thread_current not implemented!
#endif

extern bool of_thread_new(of_thread_t *thread, id (*function)(id), id data);
extern void of_thread_set_name(of_thread_t thread, const char *name);
extern bool of_thread_join(of_thread_t thread);
extern bool of_thread_detach(of_thread_t thread);
extern void OF_NO_RETURN of_thread_exit(void);
extern void of_once(of_once_t *control, void (*func)(void));
extern bool of_mutex_new(of_mutex_t *mutex);
extern bool of_mutex_lock(of_mutex_t *mutex);
extern bool of_mutex_trylock(of_mutex_t *mutex);

Modified src/threading.m from [75e009925a] to [0911130ba6].

19
20
21
22
23
24
25












26
27
28
29
30
31
32
#if defined(OF_HAVE_PTHREADS)
# include "threading_pthread.m"
#elif defined(_WIN32)
# include "threading_winapi.m"
#else
# error No threads available!
#endif













bool
of_rmutex_new(of_rmutex_t *rmutex)
{
#ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES
	pthread_mutexattr_t attr;








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







19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#if defined(OF_HAVE_PTHREADS)
# include "threading_pthread.m"
#elif defined(_WIN32)
# include "threading_winapi.m"
#else
# error No threads available!
#endif

#ifdef __HAIKU__
# include <kernel/OS.h>
#endif

void
of_thread_set_name(of_thread_t thread, const char *name)
{
#ifdef __HAIKU__
	rename_thread(get_pthread_thread_id(thread), name);
#endif
}

bool
of_rmutex_new(of_rmutex_t *rmutex)
{
#ifdef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES
	pthread_mutexattr_t attr;