1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-18 00:54:19 +00:00

Added some locking to the linux curl networking code

This commit is contained in:
jules 2018-08-31 17:47:39 +01:00
parent 6c75b0aeaa
commit b11560c4ca

View file

@ -46,6 +46,7 @@ struct CURLSymbols
std::unique_ptr<CURLSymbols> symbols (new CURLSymbols);
#if JUCE_LOAD_CURL_SYMBOLS_LAZILY
const ScopedLock sl (getLibcurlLock());
#define JUCE_INIT_CURL_SYMBOL(name) if (! symbols->loadSymbol (symbols->name, #name)) return nullptr;
#else
#define JUCE_INIT_CURL_SYMBOL(name) symbols->name = ::name;
@ -70,6 +71,14 @@ struct CURLSymbols
return symbols;
}
// liburl's curl_multi_init calls curl_global_init which is not thread safe
// so we need to get a lock during calls to curl_multi_init and curl_multi_cleanup
static CriticalSection& getLibcurlLock() noexcept
{
static CriticalSection cs;
return cs;
}
private:
CURLSymbols() = default;
@ -105,7 +114,10 @@ public:
{
jassert (symbols); // Unable to load libcurl!
multi = symbols->curl_multi_init();
{
const ScopedLock sl (CURLSymbols::getLibcurlLock());
multi = symbols->curl_multi_init();
}
if (multi != nullptr)
{
@ -175,6 +187,7 @@ public:
void cleanup()
{
const ScopedLock lock (cleanupLock);
const ScopedLock sl (CURLSymbols::getLibcurlLock());
if (curl != nullptr)
{