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 17:24:33 +0200, Jakub wrote:
> IMHO that is not a good idea, it can interfere with other projects
> that want to handle lack of __builtin_expect somehow.  Furthermore,
> __builtin_expect is only available in recent gcc (3.2+?).
> 
> libio.h uses
> #if  __GNUC__ >= 3
> # define _IO_BE(expr, res) __builtin_expect ((expr), res)
> #else
> # define _IO_BE(expr, res) (expr)
> #endif
> 
> so you could do something similar (just s/_IO_BE/__pthread_expect/ or
> similar).
> 

Thanks, changed patch as per your suggestions. Looks OK now?

Regards,
Siddhesh


nptl/ChangeLog:

2012-06-01  Siddhesh Poyarekar  <siddhesh@redhat.com>
	    Jakub Jelinek  <jakub@redhat.com>

	[BZ #14188]
	* sysdeps/pthread/pthread.h (__pthread_builtin_expect): New
	macro to wrap cases where __builtin_expect is unavailable.
	[!(defined __GNUC__ && defined __EXCEPTIONS)]
	(pthread_cleanup_push, pthread_cleanup_push_defer_np): Use it.
diff --git a/nptl/sysdeps/pthread/pthread.h b/nptl/sysdeps/pthread/pthread.h
index 88c7c25..6592219 100644
--- a/nptl/sysdeps/pthread/pthread.h
+++ b/nptl/sysdeps/pthread/pthread.h
@@ -645,6 +645,13 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
 #  endif
 # endif
 #else
+
+# if  __GNUC__ >= 3
+#  define __pthread_builtin_expect(expr, res) __builtin_expect ((expr), res)
+# else
+#  define __pthread_builtin_expect(expr, res) (expr)
+# endif
+
 /* Install a cleanup handler: ROUTINE will be called with arguments ARG
    when the thread is canceled or calls pthread_exit.  ROUTINE will also
    be called with arguments ARG when the matching pthread_cleanup_pop
@@ -659,7 +666,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 (__pthread_builtin_expect (__not_first_call, 0))			      \
       {									      \
 	__cancel_routine (__cancel_arg);				      \
 	__pthread_unwind_next (&__cancel_buf);				      \
@@ -694,7 +701,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 (__pthread_builtin_expect (__not_first_call, 0))			      \
       {									      \
 	__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]