From owner-svn-src-head@FreeBSD.ORG Wed Dec 7 15:53:14 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EB56A1065670; Wed, 7 Dec 2011 15:53:14 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 84AF78FC0A; Wed, 7 Dec 2011 15:53:14 +0000 (UTC) Received: from alf.home (alf.kiev.zoral.com.ua [10.1.1.177]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id pB7FrA5R028188 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 7 Dec 2011 17:53:10 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: from alf.home (kostik@localhost [127.0.0.1]) by alf.home (8.14.5/8.14.5) with ESMTP id pB7FrA7A011466; Wed, 7 Dec 2011 17:53:10 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by alf.home (8.14.5/8.14.5/Submit) id pB7Fr9Bm011465; Wed, 7 Dec 2011 17:53:09 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: alf.home: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 7 Dec 2011 17:53:09 +0200 From: Kostik Belousov To: David Chisnall , brooks@freebsd.org Message-ID: <20111207155309.GH50300@deviant.kiev.zoral.com.ua> References: <201112071525.pB7FPmkH044896@svn.freebsd.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="5qk+VjjGZp9A4i1j" Content-Disposition: inline In-Reply-To: <201112071525.pB7FPmkH044896@svn.freebsd.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r228322 - in head: include lib/libc/stdlib sys/sys X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Dec 2011 15:53:15 -0000 --5qk+VjjGZp9A4i1j Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Dec 07, 2011 at 03:25:48PM +0000, David Chisnall wrote: > Author: theraven > Date: Wed Dec 7 15:25:48 2011 > New Revision: 228322 > URL: http://svn.freebsd.org/changeset/base/228322 >=20 > Log: > Implement quick_exit() / at_quick_exit() from C++11 / C1x. Also add a > __noreturn macro and modify the other exiting functions to use it. > =20 > The __noreturn macro, unlike __dead2, must be used BEFORE the function. > This is in line with the C and C++ specifications that place _Noreturn = (c1x) > and [[noreturn]] (C++11) in front of the functions. As with __dead2, t= his > macro falls back to using the GCC attribute. > =20 > Unfortunately, clang currently sets the same value for the C version ma= cro > in C99 and C1x modes, so these functions are hidden by default. At some > point before 10.0, I need to go through the headers and clean up the C1= x / > C++11 visibility. > =20 > Reviewed by: brooks (mentor) And, was it approved ? > +#include > +#include > + > +/** > + * Linked list of quick exit handlers. This is simpler than the atexit() > + * version, because it is not required to support C++ destructors or > + * DSO-specific cleanups. > + */ > +struct quick_exit_handler { > + struct quick_exit_handler *next; > + void (*cleanup)(void); > +}; > + > +__attribute((weak)) > +void _ZSt9terminatev(void); Why do you need this ? You are not calling terminate() anyway, and added an explicit comment. > + > +/** > + * Lock protecting the handlers list. > + */ > +static pthread_mutex_t atexit_mutex =3D PTHREAD_MUTEX_INITIALIZER; > +/** > + * Stack of cleanup handlers. These will be invoked in reverse order wh= en=20 > + */ > +static struct quick_exit_handler *handlers; > + > +int > +at_quick_exit(void (*func)(void)) > +{ > + struct quick_exit_handler *h =3D malloc(sizeof(struct quick_exit_handle= r)); You are making initialization at the declaration place, which is not recommended by style. > + > + if (0 =3D=3D h) { Why 0 and not NULL ? Later, you use NULL. The {} are not needed. > + return 1; This shall be return (1); > + } > + h->cleanup =3D func; > + pthread_mutex_lock(&atexit_mutex); Note that libc code is careful to only call pthread mutex functions if __isthreaded variable is set. Also note that libc uses mangled names to allow the application interpositi= on of the functions. E.g. ANSI C code is allowed to have pthread_mutex_lock() function defined. > + h->next =3D handlers; > + handlers =3D h; > + pthread_mutex_unlock(&atexit_mutex); > + return 0; And this shall be return (0); > +} > + > +void quick_exit(int status) The function name shall start at the column 0. > +{ > + /* > + * XXX: The C++ spec requires us to call std::terminate if there is an > + * exception here. > + */ > + for (struct quick_exit_handler *h =3D handlers ; NULL !=3D h ; h =3D h-= >next) This fragment violates so many style requirements that I probably fail to enumerate them all. The h declaration shall go at the start of function, and not at the for statement. The opening '{' shall be placed on the line of 'for'. More, the {} bracing is not needed there. No space is needed before ';', three times. > + { > + h->cleanup(); > + } > + _Exit(status); > +} --5qk+VjjGZp9A4i1j Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk7fi+UACgkQC3+MBN1Mb4gx/gCg7LO58prTbsavYzvPC6I1zPaO szsAnR0Bk2AII9fhoa30RsMP3oEgbrXr =qn2t -----END PGP SIGNATURE----- --5qk+VjjGZp9A4i1j--