1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 #include "pal_config.h"
6 #include "pal_curlinit.h"
7 
8 #include <pthread.h>
9 #include <curl/curl.h>
10 
HttpNative_EnsureCurlIsInitialized()11 extern "C" int32_t HttpNative_EnsureCurlIsInitialized()
12 {
13     static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
14     static bool initializationAttempted = false;
15     static int32_t errorCode = -1;
16 
17     pthread_mutex_lock(&lock);
18     {
19         if (!initializationAttempted)
20         {
21             errorCode = curl_global_init(CURL_GLOBAL_ALL);
22             initializationAttempted = true;
23         }
24     }
25     pthread_mutex_unlock(&lock);
26 
27     return errorCode;
28 }
29