Skip to content

Commit

Permalink
Address concurrency-mt-unsafe warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Jan 17, 2024
1 parent 5f7c09a commit 60ef9e0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
3 changes: 1 addition & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FormatStyle: file
HeaderFilterRegex: 'silkworm/(api|core|infra|node|sentry|rpc|sync)/.+\.hpp$'
HeaderFilterRegex: 'silkworm/(capi|core|infra|node|rpc|sentry|sync|wasm)/.+\.hpp$'
WarningsAsErrors: '*'
Checks: >
abseil-*,
Expand All @@ -15,7 +15,6 @@ Checks: >
-clang-analyzer-*,
clang-diagnostic-*,
concurrency-*,
-concurrency-mt-unsafe,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-avoid-const-or-ref-data-members,
Expand Down
5 changes: 3 additions & 2 deletions silkworm/infra/common/directories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ DataDirectory DataDirectory::from_chaindata(const std::filesystem::path& chainda

std::filesystem::path silkworm::DataDirectory::get_default_storage_path() {
std::string base_dir_str{};
const char* env{std::getenv("XDG_DATA_HOME")};
// C++11 guarantees some thread safety for std::getenv
const char* env{std::getenv("XDG_DATA_HOME")}; // NOLINT(concurrency-mt-unsafe)
if (env) {
// Got storage path from docker
base_dir_str.assign(env);
Expand All @@ -148,7 +149,7 @@ std::filesystem::path silkworm::DataDirectory::get_default_storage_path() {
#else
std::string env_name{"HOME"};
#endif
env = std::getenv(env_name.c_str());
env = std::getenv(env_name.c_str()); // NOLINT(concurrency-mt-unsafe)
if (!env) {
// We don't actually know where to store data
// fallback to current directory
Expand Down
6 changes: 3 additions & 3 deletions silkworm/infra/concurrency/parallel_group_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ using namespace boost::asio::experimental;
using namespace silkworm::concurrency;
using namespace std::chrono_literals;

awaitable<void> sleep(std::chrono::milliseconds duration) {
awaitable<void> my_sleep(std::chrono::milliseconds duration) {
auto executor = co_await this_coro::executor;
steady_timer timer(executor);
timer.expires_after(duration);
Expand All @@ -47,7 +47,7 @@ awaitable<void> noop() {
}

awaitable<void> throw_op() {
co_await sleep(1ms);
co_await my_sleep(1ms);
throw std::runtime_error("throw_op");
}

Expand All @@ -67,7 +67,7 @@ awaitable<void> co_spawn_cancellation_handler_bug() {
auto strand = make_strand(executor);

try {
co_await (sleep(1s) && spawn_throw_op(strand) && spawn_noop_loop(strand));
co_await (my_sleep(1s) && spawn_throw_op(strand) && spawn_noop_loop(strand));
} catch (std::runtime_error&) {
}
}
Expand Down
9 changes: 8 additions & 1 deletion silkworm/node/bittorrent/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <libtorrent/write_resume_data.hpp>
#include <magic_enum.hpp>

#include <silkworm/core/common/assert.hpp>
#include <silkworm/core/common/base.hpp>
#include <silkworm/core/common/util.hpp>
#include <silkworm/infra/common/ensure.hpp>
Expand Down Expand Up @@ -294,10 +295,16 @@ bool BitTorrentClient::handle_alert(const lt::alert* alert) {
// When we receive the finished alert, we request to save resume data for the torrent
if (const auto* tfa = lt::alert_cast<lt::torrent_finished_alert>(alert)) {
const auto& status = tfa->handle.status();
std::tm completed_calendar_time{};
#ifdef _MSC_VER
SILKWORM_ASSERT(gmtime_s(&completed_calendar_time, &status.completed_time) == 0);
#else
SILKWORM_ASSERT(gmtime_r(&status.completed_time, &completed_calendar_time) != nullptr);
#endif
SILK_TRACE << "Torrent: " << tfa->torrent_name() << " finished download_rate: " << (status.download_rate / 1000) << " kB/s"
<< " download_payload_rate: " << (status.download_payload_rate / 1000) << " kB/s"
<< " in " << (status.completed_time - status.added_time) << " sec at "
<< std::put_time(std::gmtime(&status.completed_time), "%c %Z");
<< std::put_time(&completed_calendar_time, "%c %Z");

tfa->handle.save_resume_data(lt::torrent_handle::save_info_dict | lt::torrent_handle::flush_disk_cache);
++outstanding_resume_requests_;
Expand Down

0 comments on commit 60ef9e0

Please sign in to comment.