diff options
author | swarmer <swarmer@yandex-team.ru> | 2022-02-10 16:46:31 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:31 +0300 |
commit | 11a24635da4c4f39428b182c49a7bc35e47c9534 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /util/generic/ptr_ut.cpp | |
parent | 317da38588b7898a99fd9168571408123350012b (diff) | |
download | ydb-11a24635da4c4f39428b182c49a7bc35e47c9534.tar.gz |
Restoring authorship annotation for <swarmer@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic/ptr_ut.cpp')
-rw-r--r-- | util/generic/ptr_ut.cpp | 118 |
1 files changed, 59 insertions, 59 deletions
diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp index 6b028f410d..c2dcff23f6 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); + } +} |