Created
September 2, 2009 18:58
-
-
Save kevinw/179899 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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