ObjFW  Check-in [c701e89b83]

Overview
Comment:Use thread_local instead of __thread

If threads.h exists, the thread_local from there is used. If it doesn't,
but _Thread_local exists, it's defined to that. As a last fallback, it
is defined to __thread.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: c701e89b834e8c571d507aa0d4459e0df6f99c3f950993ca1fb7317243990259
User & Date: js on 2014-05-14 20:19:05
Other Links: manifest | tags
Context
2014-05-14
20:28
Always use __foo__ instead of foo for attributes check-in: e35b10115e user: js tags: trunk
20:19
Use thread_local instead of __thread check-in: c701e89b83 user: js tags: trunk
18:26
Try -std=c1x when -std=c11 is unavailable check-in: 7326a487c0 user: js tags: trunk
Changes

Modified configure.ac from [ba69b79b62] to [c1957ea278].

548
549
550
551
552
553
554



































555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
	AC_SUBST(USE_SRCS_THREADS, '${SRCS_THREADS}')
	AC_SUBST(USE_INCLUDES_THREADS, '${INCLUDES_THREADS}')

	AC_ARG_ENABLE(compiler-tls,
		AS_HELP_STRING([--disable-compiler-tls],
			[disable compiler thread local storage]))
	AS_IF([test x"$enable_compiler_tls" != x"no"], [



































		AC_MSG_CHECKING(whether __thread works)
		AC_TRY_LINK([
			/* It seems __thread is buggy with GCC 4.1 */
			#if __GNUC__ == 4 && __GNUC_MINOR__ < 2
			# error buggy
			#endif

			__thread int x = 0;
		], [
			x++;
		], [
			AS_IF([test x"$enable_shared" != x"no"], [
				old_OBJCFLAGS="$OBJCFLAGS"
				OBJCFLAGS="$OBJCFLAGS -fPIC"
				AC_TRY_COMPILE([
					__thread int x = 0;
				], [
					x++;
				], [
					AC_MSG_RESULT(yes)
					AC_DEFINE(OF_HAVE_COMPILER_TLS, 1,
						[Whether __thread works])
				], [
					AC_MSG_RESULT(no)
				])
				OBJCFLAGS="$old_OBJCFLAGS"
			], [
				AC_MSG_RESULT(yes)
				AC_DEFINE(OF_HAVE_COMPILER_TLS, 1,
					[Whether __thread works])
			])
		], [
			AC_MSG_RESULT(no)
		])
	])








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




















|







|







548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
	AC_SUBST(USE_SRCS_THREADS, '${SRCS_THREADS}')
	AC_SUBST(USE_INCLUDES_THREADS, '${INCLUDES_THREADS}')

	AC_ARG_ENABLE(compiler-tls,
		AS_HELP_STRING([--disable-compiler-tls],
			[disable compiler thread local storage]))
	AS_IF([test x"$enable_compiler_tls" != x"no"], [
		AC_CHECK_HEADERS(threads.h, [
			AC_DEFINE(OF_HAVE_THREADS_H, 1,
				[Whether we have threads.h])
		])

		AC_MSG_CHECKING(whether _Thread_local works)
		AC_TRY_LINK([
			static _Thread_local int x = 0;
		], [
			x++;
		], [
			AS_IF([test x"$enable_shared" != x"no"], [
				old_OBJCFLAGS="$OBJCFLAGS"
				OBJCFLAGS="$OBJCFLAGS -fPIC"
				AC_TRY_COMPILE([
					static _Thread_local int x = 0;
				], [
					x++;
				], [
					AC_MSG_RESULT(yes)
					AC_DEFINE(OF_HAVE__THREAD_LOCAL, 1,
						[Whether _Thread_local works])
				], [
					AC_MSG_RESULT(no)
				])
				OBJCFLAGS="$old_OBJCFLAGS"
			], [
				AC_MSG_RESULT(yes)
				AC_DEFINE(OF_HAVE__THREAD_LOCAL, 1,
					[Whether _Thread_local works])
			])
		], [
			AC_MSG_RESULT(no)
		])

		AC_MSG_CHECKING(whether __thread works)
		AC_TRY_LINK([
			/* It seems __thread is buggy with GCC 4.1 */
			#if __GNUC__ == 4 && __GNUC_MINOR__ < 2
			# error buggy
			#endif

			__thread int x = 0;
		], [
			x++;
		], [
			AS_IF([test x"$enable_shared" != x"no"], [
				old_OBJCFLAGS="$OBJCFLAGS"
				OBJCFLAGS="$OBJCFLAGS -fPIC"
				AC_TRY_COMPILE([
					__thread int x = 0;
				], [
					x++;
				], [
					AC_MSG_RESULT(yes)
					AC_DEFINE(OF_HAVE___THREAD, 1,
						[Whether __thread works])
				], [
					AC_MSG_RESULT(no)
				])
				OBJCFLAGS="$old_OBJCFLAGS"
			], [
				AC_MSG_RESULT(yes)
				AC_DEFINE(OF_HAVE___THREAD, 1,
					[Whether __thread works])
			])
		], [
			AC_MSG_RESULT(no)
		])
	])

Modified src/OFAutoreleasePool.m from [afda14705e] to [c6736b8348].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#endif

#import "autorelease.h"

#define MAX_CACHE_SIZE 0x20

#if defined(OF_HAVE_COMPILER_TLS)
static __thread OFAutoreleasePool **cache = NULL;
#elif defined(OF_HAVE_THREADS)
static of_tlskey_t cacheKey;
#else
static OFAutoreleasePool **cache = NULL;
#endif

@implementation OFAutoreleasePool







|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#endif

#import "autorelease.h"

#define MAX_CACHE_SIZE 0x20

#if defined(OF_HAVE_COMPILER_TLS)
static thread_local OFAutoreleasePool **cache = NULL;
#elif defined(OF_HAVE_THREADS)
static of_tlskey_t cacheKey;
#else
static OFAutoreleasePool **cache = NULL;
#endif

@implementation OFAutoreleasePool

Modified src/OFObject.h from [14f340cddc] to [b5db2a6441].

42
43
44
45
46
47
48












49
50
51
52
53
54
55
/*! @file */

#if defined(__GNUC__)
# define restrict __restrict__
#elif __STDC_VERSION__ < 199901L
# define restrict
#endif













#ifndef __has_feature
# define __has_feature(x) 0
#endif

#ifndef __has_attribute
# define __has_attribute(x) 0







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







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*! @file */

#if defined(__GNUC__)
# define restrict __restrict__
#elif __STDC_VERSION__ < 199901L
# define restrict
#endif

#if defined(OF_HAVE__THREAD_LOCAL)
# define OF_HAVE_COMPILER_TLS
# ifdef OF_HAVE_THREADS_H
#  include <threads.h>
# else
#  define thread_local _Thread_local
# endif
#elif defined(OF_HAVE___THREAD)
# define OF_HAVE_COMPILER_TLS
# define thread_local __thread
#endif

#ifndef __has_feature
# define __has_feature(x) 0
#endif

#ifndef __has_attribute
# define __has_attribute(x) 0

Modified src/autorelease.m from [81cc6ed979] to [2dc209441b].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# import "threading.h"
#endif
#import "macros.h"

#import "autorelease.h"

#if defined(OF_HAVE_COMPILER_TLS)
static __thread id *objects = NULL;
static __thread id *top = NULL;
static __thread size_t size = 0;
#elif defined(OF_HAVE_THREADS)
static of_tlskey_t objectsKey, topKey, sizeKey;
#else
static id *objects = NULL;
static id *top = NULL;
static size_t size = 0;
#endif







|
|
|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# import "threading.h"
#endif
#import "macros.h"

#import "autorelease.h"

#if defined(OF_HAVE_COMPILER_TLS)
static thread_local id *objects = NULL;
static thread_local id *top = NULL;
static thread_local size_t size = 0;
#elif defined(OF_HAVE_THREADS)
static of_tlskey_t objectsKey, topKey, sizeKey;
#else
static id *objects = NULL;
static id *top = NULL;
static size_t size = 0;
#endif

Modified src/objfw-defs.h.in from [b64e054749] to [41bed793cb].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30


31
32
33
34
#undef OF_APPLE_RUNTIME
#undef OF_BIG_ENDIAN
#undef OF_FLOAT_BIG_ENDIAN
#undef OF_HAVE_ASPRINTF
#undef OF_HAVE_ATOMIC_OPS
#undef OF_HAVE_BUILTIN_BSWAP16
#undef OF_HAVE_BUILTIN_BSWAP32
#undef OF_HAVE_BUILTIN_BSWAP64
#undef OF_HAVE_CHMOD
#undef OF_HAVE_CHOWN
#undef OF_HAVE_COMPILER_TLS
#undef OF_HAVE_FILES
#undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
#undef OF_HAVE_GCC_ATOMIC_OPS
#undef OF_HAVE_LINK
#undef OF_HAVE_MAX_ALIGN_T
#undef OF_HAVE_NETINET_IN_H
#undef OF_HAVE_OSATOMIC
#undef OF_HAVE_OSATOMIC_64
#undef OF_HAVE_PIPE
#undef OF_HAVE_PLUGINS
#undef OF_HAVE_PROCESSES
#undef OF_HAVE_PTHREADS
#undef OF_HAVE_PTHREAD_SPINLOCKS
#undef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES
#undef OF_HAVE_SCHED_YIELD
#undef OF_HAVE_SOCKETS
#undef OF_HAVE_SYMLINK
#undef OF_HAVE_SYS_SOCKET_H
#undef OF_HAVE_THREADS


#undef OF_NINTENDO_DS
#undef OF_OBJFW_RUNTIME
#undef OF_UNIVERSAL
#undef SIZE_MAX










<



















>
>




1
2
3
4
5
6
7
8
9
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#undef OF_APPLE_RUNTIME
#undef OF_BIG_ENDIAN
#undef OF_FLOAT_BIG_ENDIAN
#undef OF_HAVE_ASPRINTF
#undef OF_HAVE_ATOMIC_OPS
#undef OF_HAVE_BUILTIN_BSWAP16
#undef OF_HAVE_BUILTIN_BSWAP32
#undef OF_HAVE_BUILTIN_BSWAP64
#undef OF_HAVE_CHMOD
#undef OF_HAVE_CHOWN

#undef OF_HAVE_FILES
#undef OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
#undef OF_HAVE_GCC_ATOMIC_OPS
#undef OF_HAVE_LINK
#undef OF_HAVE_MAX_ALIGN_T
#undef OF_HAVE_NETINET_IN_H
#undef OF_HAVE_OSATOMIC
#undef OF_HAVE_OSATOMIC_64
#undef OF_HAVE_PIPE
#undef OF_HAVE_PLUGINS
#undef OF_HAVE_PROCESSES
#undef OF_HAVE_PTHREADS
#undef OF_HAVE_PTHREAD_SPINLOCKS
#undef OF_HAVE_RECURSIVE_PTHREAD_MUTEXES
#undef OF_HAVE_SCHED_YIELD
#undef OF_HAVE_SOCKETS
#undef OF_HAVE_SYMLINK
#undef OF_HAVE_SYS_SOCKET_H
#undef OF_HAVE_THREADS
#undef OF_HAVE___THREAD
#undef OF_HAVE__THREAD_LOCAL
#undef OF_NINTENDO_DS
#undef OF_OBJFW_RUNTIME
#undef OF_UNIVERSAL
#undef SIZE_MAX