This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][BZ #14188] Allow pthread_cleanup_push to build withcompilers other than gcc


On Fri,  1 Jun 2012 12:41:48 -0700 (PDT), Roland wrote:
> This is the only use of __builtin_expect in a public header now.
> But it seems reasonably likely that we'll have others eventually.
> So my inclination would be to put the macro in sys/cdefs.h and give
> it a different name.  (Or perhaps also slightly different semantics,
> e.g. __glibc_unlikely(BOOL).)
> 

OK, updated patch attached. I guess it would be a good idea to mandate
use of __glibc_unlikely() wherever applicable, purely because it makes
code prettier. It might not be worth hunting down and changing
everything in one go, but at least to ensure that future uses (and
modifications) of __builtin_expect(cond, 0) be discouraged in favour of
__glibc_unlikely throughout the code base.

Tested with tinycc (http://bellard.org/tcc/) to verify that correct
code is generated for pthread_cleanup_push and also with gcc on Fedora
to verify that there are no regressions.

Regards,
Siddhesh


ChangeLog:
2012-06-02  Siddhesh Poyarekar  <siddhesh@redhat.com>
	    Jakub Jelinek  <jakub@redhat.com>

	[BZ #14188]
	* misc/sys/cdefs.h (__glibc_unlikely): New macro to wrap cases
	where __builtin_expect is unavailable.


nptl/ChangeLog:
2012-06-02  Siddhesh Poyarekar  <siddhesh@redhat.com>
	    Jakub Jelinek  <jakub@redhat.com>

	[BZ #14188]
	* sysdeps/pthread/pthread.h
	[!(defined __GNUC__ && defined __EXCEPTIONS)]
	(pthread_cleanup_push, pthread_cleanup_push_defer_np): Use
	__libc_unlikely instead of __builtin_expect.
diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h
index f4e96db..b94147e 100644
--- a/misc/sys/cdefs.h
+++ b/misc/sys/cdefs.h
@@ -369,6 +369,12 @@
 # endif
 #endif
 
+#if __GNUC__ >= 3
+# define __glibc_unlikely(cond) __builtin_expect((cond), 0)
+#else
+# define __glibc_unlikely(cond) (cond)
+#endif
+
 #include <bits/wordsize.h>
 
 #if defined __LONG_DOUBLE_MATH_OPTIONAL && defined __NO_LONG_DOUBLE_MATH
diff --git a/nptl/sysdeps/pthread/pthread.h b/nptl/sysdeps/pthread/pthread.h
index 88c7c25..246c1a0 100644
--- a/nptl/sysdeps/pthread/pthread.h
+++ b/nptl/sysdeps/pthread/pthread.h
@@ -659,7 +659,7 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
     void *__cancel_arg = (arg);						      \
     int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *)     \
 					__cancel_buf.__cancel_jmp_buf, 0);    \
-    if (__builtin_expect (__not_first_call, 0))				      \
+    if (__glibc_unlikely (__not_first_call))				      \
       {									      \
 	__cancel_routine (__cancel_arg);				      \
 	__pthread_unwind_next (&__cancel_buf);				      \
@@ -694,7 +694,7 @@ extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf)
     void *__cancel_arg = (arg);						      \
     int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *)     \
 					__cancel_buf.__cancel_jmp_buf, 0);    \
-    if (__builtin_expect (__not_first_call, 0))				      \
+    if (__glibc_unlikely (__not_first_call))			      \
       {									      \
 	__cancel_routine (__cancel_arg);				      \
 	__pthread_unwind_next (&__cancel_buf);				      \

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]