From patchwork Fri Jul 15 15:05:52 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 104835 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 74609B6F54 for ; Sat, 16 Jul 2011 01:06:13 +1000 (EST) Received: (qmail 11034 invoked by alias); 15 Jul 2011 15:06:08 -0000 Received: (qmail 11010 invoked by uid 22791); 15 Jul 2011 15:06:06 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 15 Jul 2011 15:05:47 +0000 Received: from rtcsinet22.oracle.com (rtcsinet22.oracle.com [66.248.204.30]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p6FF5hCc028781 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 15 Jul 2011 15:05:45 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by rtcsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p6FF5fOK025493 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 15 Jul 2011 15:05:42 GMT Received: from abhmt105.oracle.com (abhmt105.oracle.com [141.146.116.57]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p6FF5afb022275; Fri, 15 Jul 2011 10:05:36 -0500 Received: from [192.168.1.4] (/79.51.11.127) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 15 Jul 2011 08:05:35 -0700 Message-ID: <4E205750.5050302@oracle.com> Date: Fri, 15 Jul 2011 17:05:52 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: Jakub Jelinek CC: Jason Merrill , "gcc-patches@gcc.gnu.org" , libstdc++ , Ian Lance Taylor Subject: Re: [v3] libstdc++/49745 (review required for the gthr-posix.h changes) References: <4E2036FA.8020901@oracle.com> <4E204270.5050508@redhat.com> <20110715134540.GL2687@tyan-ft48-01.lab.bos.redhat.com> In-Reply-To: <20110715134540.GL2687@tyan-ft48-01.lab.bos.redhat.com> X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, > gthr-posix.h already uses other macros defined by other library > headers, like _LIBOBJC. gthr-posix-conf.h looks like an overkill to me, > but if e.g. libstdc++ headers defined a 0/1 macro always > (_GTHREAD_USE_TIMEDLOCK 0 would mean don't define it, _GTHREAD_USE_TIMEDLOCK 1 > would mean you can safely assume timedlock is available, and not presence > of that macro would lead to inclusion of unistd.h and deciding itself > based on _POSIX_TIMEOUTS: > > #ifndef _GTHREAD_USE_TIMEDLOCK > #include > #ifdef _POSIX_TIMEOUTS > #if _POSIX_TIMEOUTS>= 0 > #define _GTHREAD_USE_TIMEDLOCK 1 > #else > #define _GTHREAD_USE_TIMEDLOCK 0 > #else > #define _GTHREAD_USE_TIMEDLOCK 0 > #endif > and use > > #if _GTHREAD_USE_TIMEDLOCK > ... > #endif > I'm finishing testing the below. Appears to work well, so far... Paolo. //////////////////// /gcc 2011-07-15 Paolo Carlini Jakub Jelinek Jonathan Wakely PR libstdc++/49745 * gthr-posix.h: Do not include unconditionally; use _GTHREADS_USE_MUTEX_TIMEDLOCK instead of _POSIX_TIMEOUTS. /libstdc++-v3 2011-07-15 Paolo Carlini Jakub Jelinek PR libstdc++/49745 * acinclude.m4 ([GLIBCXX_CHECK_GTHREADS]): Check separately for _POSIX_TIMEOUTS and define _GTHREADS_USE_MUTEX_TIMEDLOCK. * libstdc++-v3/libsupc++/guard.cc: Include . * testsuite/17_intro/headers/c++1998/49745.cc: New. * configure: Regenerate. * config.h.in: Likewise. Index: libstdc++-v3/libsupc++/guard.cc =================================================================== --- libstdc++-v3/libsupc++/guard.cc (revision 176310) +++ libstdc++-v3/libsupc++/guard.cc (working copy) @@ -35,6 +35,7 @@ && defined(_GLIBCXX_ATOMIC_BUILTINS_4) && defined(_GLIBCXX_HAVE_LINUX_FUTEX) # include # include +# include # define _GLIBCXX_USE_FUTEX # define _GLIBCXX_FUTEX_WAIT 0 # define _GLIBCXX_FUTEX_WAKE 1 Index: libstdc++-v3/testsuite/17_intro/headers/c++1998/49745.cc =================================================================== --- libstdc++-v3/testsuite/17_intro/headers/c++1998/49745.cc (revision 0) +++ libstdc++-v3/testsuite/17_intro/headers/c++1998/49745.cc (revision 0) @@ -0,0 +1,22 @@ +// { dg-do compile { target *-*-linux* } } + +// Copyright (C) 2011 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// libstdc++/49745 +#include +int truncate = 0; Index: libstdc++-v3/acinclude.m4 =================================================================== --- libstdc++-v3/acinclude.m4 (revision 176310) +++ libstdc++-v3/acinclude.m4 (working copy) @@ -3155,6 +3155,22 @@ ac_save_CXXFLAGS="$CXXFLAGS" CXXFLAGS="$CXXFLAGS -fno-exceptions -I${toplevel_srcdir}/gcc" + AC_MSG_CHECKING([check whether it can be safely assumed that mutex_timedlock is available]) + + AC_TRY_COMPILE([#include ], + [ + #if !defined(_POSIX_TIMEOUTS) || _POSIX_TIMEOUTS < 0 + #error + #endif + ], [ac_gthread_use_mutex_timedlock=1], [ac_gthread_use_mutex_timedlock=0]) + + AC_DEFINE_UNQUOTED(_GTHREAD_USE_MUTEX_TIMEDLOCK, $ac_gthread_use_mutex_timedlock, + [Define to 1 if mutex_timedlock is available.]) + + if test $ac_gthread_use_mutex_timedlock = 1 ; then res_mutex_timedlock=yes ; + else res_mutex_timedlock=no ; fi + AC_MSG_RESULT([$res_mutex_timedlock]) + target_thread_file=`$CXX -v 2>&1 | sed -n 's/^Thread model: //p'` case $target_thread_file in posix) @@ -3163,7 +3179,10 @@ AC_MSG_CHECKING([for gthreads library]) - AC_TRY_COMPILE([#include "gthr.h"], + AC_TRY_COMPILE([ + #include "gthr.h" + #include + ], [ #ifndef __GTHREADS_CXX0X #error Index: gcc/gthr-posix.h =================================================================== --- gcc/gthr-posix.h (revision 176310) +++ gcc/gthr-posix.h (working copy) @@ -1,7 +1,7 @@ /* Threads compatibility routines for libgcc2 and libobjc. */ /* Compile this one with gcc. */ /* Copyright (C) 1997, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, - 2008, 2009, 2010 Free Software Foundation, Inc. + 2008, 2009, 2010, 2011 Free Software Foundation, Inc. This file is part of GCC. @@ -39,8 +39,17 @@ #endif #include -#include +#if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \ + || !defined(_GTHREAD_USE_MUTEX_TIMEDLOCK)) +# include +# if defined(_POSIX_TIMEOUTS) && _POSIX_TIMEOUTS >= 0 +# define _GTHREAD_USE_MUTEX_TIMEDLOCK 1 +# else +# define _GTHREAD_USE_MUTEX_TIMEDLOCK 0 +# endif +#endif + typedef pthread_t __gthread_t; typedef pthread_key_t __gthread_key_t; typedef pthread_once_t __gthread_once_t; @@ -100,11 +109,9 @@ __gthrw3(pthread_mutex_lock) __gthrw3(pthread_mutex_trylock) -#ifdef _POSIX_TIMEOUTS -#if _POSIX_TIMEOUTS >= 0 +#if _GTHREAD_USE_MUTEX_TIMEDLOCK __gthrw3(pthread_mutex_timedlock) #endif -#endif /* _POSIX_TIMEOUTS */ __gthrw3(pthread_mutex_unlock) __gthrw3(pthread_mutex_init) __gthrw3(pthread_mutex_destroy) @@ -131,11 +138,9 @@ __gthrw(pthread_mutex_lock) __gthrw(pthread_mutex_trylock) -#ifdef _POSIX_TIMEOUTS -#if _POSIX_TIMEOUTS >= 0 +#if _GTHREAD_USE_MUTEX_TIMEDLOCK __gthrw(pthread_mutex_timedlock) #endif -#endif /* _POSIX_TIMEOUTS */ __gthrw(pthread_mutex_unlock) __gthrw(pthread_mutex_init) __gthrw(pthread_mutex_destroy) @@ -753,8 +758,7 @@ return 0; } -#ifdef _POSIX_TIMEOUTS -#if _POSIX_TIMEOUTS >= 0 +#if _GTHREAD_USE_MUTEX_TIMEDLOCK static inline int __gthread_mutex_timedlock (__gthread_mutex_t *__mutex, const __gthread_time_t *__abs_timeout) @@ -765,7 +769,6 @@ return 0; } #endif -#endif static inline int __gthread_mutex_unlock (__gthread_mutex_t *__mutex) @@ -811,8 +814,7 @@ return __gthread_mutex_trylock (__mutex); } -#ifdef _POSIX_TIMEOUTS -#if _POSIX_TIMEOUTS >= 0 +#if _GTHREAD_USE_MUTEX_TIMEDLOCK static inline int __gthread_recursive_mutex_timedlock (__gthread_recursive_mutex_t *__mutex, const __gthread_time_t *__abs_timeout) @@ -820,7 +822,6 @@ return __gthread_mutex_timedlock (__mutex, __abs_timeout); } #endif -#endif static inline int __gthread_recursive_mutex_unlock (__gthread_recursive_mutex_t *__mutex)