Skip to content

Instantly share code, notes, and snippets.

@kevinw
Created September 2, 2009 18:58
Show Gist options
  • Save kevinw/179899 to your computer and use it in GitHub Desktop.
Save kevinw/179899 to your computer and use it in GitHub Desktop.
static Mutex* sharedResourceMutex(curl_lock_data data) {
DEFINE_STATIC_LOCAL(Mutex, cookieMutex, ());
DEFINE_STATIC_LOCAL(Mutex, dnsMutex, ());
switch (data) {
case CURL_LOCK_DATA_COOKIE:
return &cookieMutex;
case CURL_LOCK_DATA_DNS:
return &dnsMutex;
default:
return NULL;
}
}
// libcurl does not implement its own thread synchronization primitives.
// these two functions provide mutexes for cookies, and for the global DNS
// cache.
static void curl_lock_callback(CURL* handle, curl_lock_data data, curl_lock_access access, void* userPtr)
{
if (Mutex* mutex = sharedResourceMutex(data))
mutex->lock();
}
static void curl_unlock_callback(CURL* handle, curl_lock_data data, void* userPtr)
{
if (Mutex* mutex = sharedResourceMutex(data))
mutex->unlock();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment