Skip to content

Commit 818f8d6

Browse files
authored
Merge pull request #92 from JacobMao/master
fixed a bug which is cased by no threadsafe.
2 parents 5fde5cc + b450644 commit 818f8d6

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

include/curl_exception.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <utility>
3333
#include <vector>
3434
#include <algorithm>
35+
#include <mutex>
3536
#include <curl/curl.h>
3637

3738
#include "curl_config.h"
@@ -74,6 +75,11 @@ namespace curl {
7475
* when an exception is thrown.
7576
*/
7677
static curlcpp_traceback traceback;
78+
79+
/**
80+
* Locker for inserting traceback.
81+
*/
82+
static std::mutex tracebackLocker;
7783
};
7884

7985
// Implementation of print_traceback

src/curl_exception.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ using curl::curlcpp_traceback;
1111
// Need to define the traceback here to separate declaration from definition, or we'll get a linker error.
1212
curlcpp_traceback curl::curl_exception::traceback;
1313

14+
std::mutex curl::curl_exception::tracebackLocker;
15+
1416
// Constructor implementation. Every call will push into the calls stack the function name and the error occurred.
1517
curl_exception::curl_exception(const std::string &error, const std::string &fun_name) {
18+
curl_exception::tracebackLocker.lock();
19+
1620
curl_exception::traceback.insert(curl_exception::traceback.begin(),curlcpp_traceback_object(error,fun_name));
21+
22+
curl_exception::tracebackLocker.unlock();
1723
}
1824

1925
// Implementation of destructor.

0 commit comments

Comments
 (0)