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, Jun 01, 2012 at 06:30:39PM +0530, Siddhesh Poyarekar wrote:
> As reported in bz #14188, programs using pthread_cleanup_push do not
> compile cleanly with compilers that do not implement __builtin_*
> functions. Attached trivial patch eliminates the __builtin_expect inside
> pthread_cleanup_push macro definition in pthread.h if the compiler is
> not gcc.

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).

> 2012-06-01  Siddhesh Poyarekar  <siddhesh@redhat.com>
> 
> 	[BZ #14188]
> 	* sysdeps/pthread/pthread.h [!__GNUC__]: Define __builtin_expect
> 	when compiler is not gcc.

> diff --git a/nptl/sysdeps/pthread/pthread.h b/nptl/sysdeps/pthread/pthread.h
> index 88c7c25..636ca45 100644
> --- a/nptl/sysdeps/pthread/pthread.h
> +++ b/nptl/sysdeps/pthread/pthread.h
> @@ -645,6 +645,11 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame)
>  #  endif
>  # endif
>  #else
> +
> +# ifndef __GNUC__
> +#  define __builtin_expect(cond, unused) (cond)
> +# 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

	Jakub


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