summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/tdutils/test/HazardPointers.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2022-11-30 17:48:47 +0300
committerGeorge Hazan <ghazan@miranda.im>2022-11-30 17:48:47 +0300
commit0ece30dc7c0e34b4c5911969b8fa99c33c6d023c (patch)
tree671325d3fec09b999411e4e3ab84ef8259261818 /protocols/Telegram/tdlib/td/tdutils/test/HazardPointers.cpp
parent46c53ffc6809c67e4607e99951a2846c382b63b2 (diff)
Telegram: update for TDLIB
Diffstat (limited to 'protocols/Telegram/tdlib/td/tdutils/test/HazardPointers.cpp')
-rw-r--r--protocols/Telegram/tdlib/td/tdutils/test/HazardPointers.cpp16
1 files changed, 9 insertions, 7 deletions
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 <atomic>
@@ -15,7 +17,7 @@
#if !TD_THREAD_UNSUPPORTED
TEST(HazardPointers, stress) {
struct Node {
- std::atomic<std::string *> name_;
+ std::atomic<std::string *> 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<decltype(hazard_pointers)>::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<int>(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