From 0ece30dc7c0e34b4c5911969b8fa99c33c6d023c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 30 Nov 2022 17:48:47 +0300 Subject: Telegram: update for TDLIB --- .../Telegram/tdlib/td/tdutils/test/HazardPointers.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'protocols/Telegram/tdlib/td/tdutils/test/HazardPointers.cpp') diff --git a/protocols/Telegram/tdlib/td/tdutils/test/HazardPointers.cpp b/protocols/Telegram/tdlib/td/tdutils/test/HazardPointers.cpp index 36b0570530..0c4174db0f 100644 --- a/protocols/Telegram/tdlib/td/tdutils/test/HazardPointers.cpp +++ b/protocols/Telegram/tdlib/td/tdutils/test/HazardPointers.cpp @@ -1,13 +1,15 @@ // -// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2018 +// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2022 // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // +#include "td/utils/common.h" #include "td/utils/HazardPointers.h" #include "td/utils/logging.h" #include "td/utils/port/thread.h" #include "td/utils/Random.h" +#include "td/utils/Slice.h" #include "td/utils/tests.h" #include @@ -15,7 +17,7 @@ #if !TD_THREAD_UNSUPPORTED TEST(HazardPointers, stress) { struct Node { - std::atomic name_; + std::atomic name_{nullptr}; char pad[64]; }; int threads_n = 10; @@ -25,16 +27,16 @@ TEST(HazardPointers, stress) { int thread_id = 0; for (auto &thread : threads) { thread = td::thread([&, thread_id] { - auto holder = hazard_pointers.get_holder(thread_id, 0); + std::remove_reference_t::Holder holder(hazard_pointers, thread_id, 0); for (int i = 0; i < 1000000; i++) { auto &node = nodes[td::Random::fast(0, threads_n - 1)]; auto *str = holder.protect(node.name_); if (str) { - CHECK(*str == "one" || *str == "twotwo"); + CHECK(*str == td::Slice("one") || *str == td::Slice("twotwo")); } holder.clear(); if (td::Random::fast(0, 5) == 0) { - std::string *new_str = new std::string(td::Random::fast(0, 1) == 0 ? "one" : "twotwo"); + auto *new_str = new td::string(td::Random::fast_bool() ? "one" : "twotwo"); if (node.name_.compare_exchange_strong(str, new_str, std::memory_order_acq_rel)) { hazard_pointers.retire(thread_id, str); } else { @@ -48,11 +50,11 @@ TEST(HazardPointers, stress) { for (auto &thread : threads) { thread.join(); } - LOG(ERROR) << "Undeleted pointers: " << hazard_pointers.to_delete_size_unsafe(); + LOG(INFO) << "Undeleted pointers: " << hazard_pointers.to_delete_size_unsafe(); CHECK(static_cast(hazard_pointers.to_delete_size_unsafe()) <= threads_n * threads_n); for (int i = 0; i < threads_n; i++) { hazard_pointers.retire(i); } CHECK(hazard_pointers.to_delete_size_unsafe() == 0); } -#endif //!TD_THREAD_UNSUPPORTED +#endif -- cgit v1.2.3