@@ -7,33 +7,32 @@ namespace cpr {
77ConnectionPool::ConnectionPool () {
88 CURLSH* curl_share = curl_share_init ();
99 this ->connection_mutex_ = std::make_shared<std::mutex>();
10-
10+
1111 auto lock_f = +[](CURL* /* handle*/ , curl_lock_data /* data*/ , curl_lock_access /* access*/ , void * userptr) {
1212 std::mutex* lock = static_cast <std::mutex*>(userptr);
1313 lock->lock (); // cppcheck-suppress localMutex // False positive: mutex is used as callback for libcurl, not local scope
1414 };
15-
15+
1616 auto unlock_f = +[](CURL* /* handle*/ , curl_lock_data /* data*/ , void * userptr) {
1717 std::mutex* lock = static_cast <std::mutex*>(userptr);
1818 lock->unlock ();
1919 };
20-
20+
2121 curl_share_setopt (curl_share, CURLSHOPT_SHARE, CURL_LOCK_DATA_CONNECT);
2222 curl_share_setopt (curl_share, CURLSHOPT_USERDATA, this ->connection_mutex_ .get ());
2323 curl_share_setopt (curl_share, CURLSHOPT_LOCKFUNC, lock_f);
2424 curl_share_setopt (curl_share, CURLSHOPT_UNLOCKFUNC, unlock_f);
25-
26- this ->curl_sh_ = std::shared_ptr<CURLSH>(curl_share,
27- [](CURLSH* ptr) {
28- // Make sure to reset callbacks before cleanup to avoid deadlocks
29- curl_share_setopt (ptr, CURLSHOPT_LOCKFUNC, nullptr );
30- curl_share_setopt (ptr, CURLSHOPT_UNLOCKFUNC, nullptr );
31- curl_share_cleanup (ptr);
32- });
25+
26+ this ->curl_sh_ = std::shared_ptr<CURLSH>(curl_share, [](CURLSH* ptr) {
27+ // Make sure to reset callbacks before cleanup to avoid deadlocks
28+ curl_share_setopt (ptr, CURLSHOPT_LOCKFUNC, nullptr );
29+ curl_share_setopt (ptr, CURLSHOPT_UNLOCKFUNC, nullptr );
30+ curl_share_cleanup (ptr);
31+ });
3332}
3433
3534void ConnectionPool::SetupHandler (CURL* easy_handler) const {
3635 curl_easy_setopt (easy_handler, CURLOPT_SHARE, this ->curl_sh_ .get ());
3736}
3837
39- } // namespace cpr
38+ } // namespace cpr
0 commit comments