aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/ptr_ut.cpp
diff options
context:
space:
mode:
authorswarmer <swarmer@yandex-team.ru>2022-02-10 16:46:31 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:31 +0300
commit317da38588b7898a99fd9168571408123350012b (patch)
tree25eebc31526019ad39a6c1b13f492963d97ba439 /util/generic/ptr_ut.cpp
parent3b2241461d41d41ba1a706b0750c4f0f55c344f6 (diff)
downloadydb-317da38588b7898a99fd9168571408123350012b.tar.gz
Restoring authorship annotation for <swarmer@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic/ptr_ut.cpp')
-rw-r--r--util/generic/ptr_ut.cpp118
1 files changed, 59 insertions, 59 deletions
diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp
index c2dcff23f6..6b028f410d 100644
--- a/util/generic/ptr_ut.cpp
+++ b/util/generic/ptr_ut.cpp
@@ -25,7 +25,7 @@ class TPointerTest: public TTestBase {
UNIT_TEST(TestIntrPtr);
UNIT_TEST(TestIntrusiveConvertion);
UNIT_TEST(TestIntrusiveConstConvertion);
- UNIT_TEST(TestIntrusiveConstConstruction);
+ UNIT_TEST(TestIntrusiveConstConstruction);
UNIT_TEST(TestMakeIntrusive);
UNIT_TEST(TestCopyOnWritePtr1);
UNIT_TEST(TestCopyOnWritePtr2);
@@ -77,7 +77,7 @@ private:
void TestIntrPtr();
void TestIntrusiveConvertion();
void TestIntrusiveConstConvertion();
- void TestIntrusiveConstConstruction();
+ void TestIntrusiveConstConstruction();
void TestMakeIntrusive();
void TestCopyOnWritePtr1();
void TestCopyOnWritePtr2();
@@ -776,60 +776,60 @@ void TPointerTest::TestRefCountedPtrsInHashSet() {
TestRefCountedPtrsInHashSetImpl<A, TIntrusivePtr<A, TCustomIntrusivePtrOps>>();
TestRefCountedPtrsInHashSetImpl<A, TIntrusiveConstPtr<A, TCustomIntrusivePtrOps>>();
}
-
-class TRefCountedWithStatistics: public TNonCopyable {
-public:
- struct TExternalCounter {
- TAtomic Counter{0};
- TAtomic Increments{0};
- };
-
- TRefCountedWithStatistics(TExternalCounter& cnt)
- : ExternalCounter_(cnt)
- {
- ExternalCounter_ = {}; // reset counters
- }
-
- void Ref() noexcept {
- AtomicIncrement(ExternalCounter_.Counter);
- AtomicIncrement(ExternalCounter_.Increments);
- }
-
- void UnRef() noexcept {
- if (AtomicDecrement(ExternalCounter_.Counter) == 0) {
- TDelete::Destroy(this);
- }
- }
-
- void DecRef() noexcept {
- Y_VERIFY(AtomicDecrement(ExternalCounter_.Counter) != 0);
- }
-
-private:
- TExternalCounter& ExternalCounter_;
-};
-
-void TPointerTest::TestIntrusiveConstConstruction() {
- {
- TRefCountedWithStatistics::TExternalCounter cnt;
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0);
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 0);
- TIntrusivePtr<TRefCountedWithStatistics> i{MakeIntrusive<TRefCountedWithStatistics>(cnt)};
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 1);
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1);
- i.Reset();
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0);
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1);
- }
- {
- TRefCountedWithStatistics::TExternalCounter cnt;
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0);
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 0);
- TIntrusiveConstPtr<TRefCountedWithStatistics> c{MakeIntrusive<TRefCountedWithStatistics>(cnt)};
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 1);
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1);
- c.Reset();
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0);
- UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1);
- }
-}
+
+class TRefCountedWithStatistics: public TNonCopyable {
+public:
+ struct TExternalCounter {
+ TAtomic Counter{0};
+ TAtomic Increments{0};
+ };
+
+ TRefCountedWithStatistics(TExternalCounter& cnt)
+ : ExternalCounter_(cnt)
+ {
+ ExternalCounter_ = {}; // reset counters
+ }
+
+ void Ref() noexcept {
+ AtomicIncrement(ExternalCounter_.Counter);
+ AtomicIncrement(ExternalCounter_.Increments);
+ }
+
+ void UnRef() noexcept {
+ if (AtomicDecrement(ExternalCounter_.Counter) == 0) {
+ TDelete::Destroy(this);
+ }
+ }
+
+ void DecRef() noexcept {
+ Y_VERIFY(AtomicDecrement(ExternalCounter_.Counter) != 0);
+ }
+
+private:
+ TExternalCounter& ExternalCounter_;
+};
+
+void TPointerTest::TestIntrusiveConstConstruction() {
+ {
+ TRefCountedWithStatistics::TExternalCounter cnt;
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 0);
+ TIntrusivePtr<TRefCountedWithStatistics> i{MakeIntrusive<TRefCountedWithStatistics>(cnt)};
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 1);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1);
+ i.Reset();
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1);
+ }
+ {
+ TRefCountedWithStatistics::TExternalCounter cnt;
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 0);
+ TIntrusiveConstPtr<TRefCountedWithStatistics> c{MakeIntrusive<TRefCountedWithStatistics>(cnt)};
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 1);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1);
+ c.Reset();
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Counter), 0);
+ UNIT_ASSERT_VALUES_EQUAL(AtomicGet(cnt.Increments), 1);
+ }
+}