cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_global_init performance

From: Tim Ruehsen <tim.ruehsen_at_gmx.de>
Date: Thu, 29 Aug 2013 16:26:34 +0200

On Thursday 29 August 2013 12:32:00 Daniel Stenberg wrote:
> On Thu, 29 Aug 2013, Tim Ruehsen wrote:
> > It looks like that curl_global_init() initalizes OpenSSL though SSL is not
> > needed. Kcachegrind show that SSL_load_error_strings() is alone
> > responsible
> > for nearly 50% impact.
> >
> > Isn't it possible to only initialize SSL stuff when needed ?
>
> Not easily, no.
>
> A major problem for libcurl (but not for wget) is that OpenSSL (and a few
> other libs) don't provide thread-safe init functions. We need to make sure
> that they are called in a safe way if we want to have the rest of the API
> work fine in threads. Our way of making sure is to have curl_global_init().
>
> A can think of other ways of doing it, but I can't think of a way that we
> can introduce now without changing API/ABI...

Wouldn't be the typical init stuff in this case look like

#ifdef HAVE_THREADS
static int init;
mutex lock
if (++init==1)
        SSL init
mutex unlock
#else
        SSL init
#endif

Using a non-threading libcurl in a threaded program would need to take some
care (of course).

Regards, Tim

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-08-29