Skip to content

Commit

Permalink
Apply code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZhihao-723 committed Jun 26, 2024
1 parent ca8e0c1 commit cec8d62
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 2 additions & 6 deletions components/core/src/clp/CurlGlobalInstance.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "CurlGlobalInstance.hpp"

#include <cstddef>
#include <mutex>

#include <curl/curl.h>
Expand All @@ -9,11 +8,8 @@
#include "ErrorCode.hpp"

namespace clp {
std::mutex CurlGlobalInstance::m_global_mutex;
size_t CurlGlobalInstance::m_num_living_instances{0};

CurlGlobalInstance::CurlGlobalInstance() {
std::unique_lock<std::mutex> const global_lock{m_global_mutex};
std::lock_guard<std::mutex> const global_lock{m_global_mutex};
if (0 == m_num_living_instances) {
if (auto const err{curl_global_init(CURL_GLOBAL_ALL)}; CURLE_OK != err) {
throw CurlOperationFailed(
Expand All @@ -29,7 +25,7 @@ CurlGlobalInstance::CurlGlobalInstance() {
}

CurlGlobalInstance::~CurlGlobalInstance() {
std::unique_lock<std::mutex> const global_lock{m_global_mutex};
std::lock_guard<std::mutex> const global_lock{m_global_mutex};
--m_num_living_instances;
if (0 == m_num_living_instances) {
#if defined(__APPLE__)
Expand Down
8 changes: 4 additions & 4 deletions components/core/src/clp/CurlGlobalInstance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace clp {
/**
* Class to wrap `libcurl`'s global initialization/de-initialization calls. Before using any
* `libcurl` functionalities, an instance of this function must be created to ensure underlying
* Class to wrap `libcurl`'s global initialization/de-initialization calls using RAII. Before using
* any `libcurl` functionalities, an instance of this function must be created to ensure underlying
* `libcurl` resources have been initialized. This class maintains a static reference count to all
* the living instances. De-initialization happens when the reference count reaches 0.
*/
Expand All @@ -26,8 +26,8 @@ class CurlGlobalInstance {
~CurlGlobalInstance();

private:
static std::mutex m_global_mutex;
static size_t m_num_living_instances;
static inline std::mutex m_global_mutex;
static inline size_t m_num_living_instances;
};
} // namespace clp

Expand Down

0 comments on commit cec8d62

Please sign in to comment.