From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51411) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsaD5-00018n-RP for qemu-devel@nongnu.org; Wed, 13 May 2015 13:12:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YsaCz-0003QU-4G for qemu-devel@nongnu.org; Wed, 13 May 2015 13:12:43 -0400 Received: from mail-wi0-x22e.google.com ([2a00:1450:400c:c05::22e]:35838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YsaCy-0003Pq-Tm for qemu-devel@nongnu.org; Wed, 13 May 2015 13:12:37 -0400 Received: by widdi4 with SMTP id di4so207802395wid.0 for ; Wed, 13 May 2015 10:12:36 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <55538600.8090303@redhat.com> Date: Wed, 13 May 2015 19:12:32 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1429280557-8887-1-git-send-email-berrange@redhat.com> <1429280557-8887-9-git-send-email-berrange@redhat.com> <20150513170415.GA28703@redhat.com> In-Reply-To: <20150513170415.GA28703@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v1 RFC 08/34] crypto: introduce new module for computing hash digests List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" , qemu-devel@nongnu.org Cc: Gerd Hoffmann , Stefan Hajnoczi On 13/05/2015 19:04, Daniel P. Berrange wrote: > I'm thinking perhaps a better approach could be for the crypto related > APIs to call qcrypto_init() on an as-needed basis. The downside would > be that this could delay the point at which the user sees a gnutls > initialization failure to only after QEMU has been running for a while, > instead of being upfront at startup. The plus side is obviously that > we'd not need to update every binary program main() method. > > I notice though that QEMU does not make use of pthread_once() for > global initializers. Is there any particular reason for this ? With > this crypto code it is not safe to rely on being single threaded, > since the crypto code can be invoked from I/O threads as well as > the main event loop. So ideally I would use a pthread_once() instead > of having a static 'bool is_initialized' protected by a pthread_mutex Yes---though you'd use a GOnce instead for portability. In fact you would likely keep both, and use a GOnce from qcrypto_init. Then you can always call qcrypto_init from main if that helps making early failures clearer. Paolo