Commit 81959105 authored by Chad Parry's avatar Chad Parry Committed by Facebook Github Bot 3

Switch HHWheelTimer::SharedPtr to a standard shared pointer

Summary:
As part of my campaign to get `HHWheelTimer` away from intrusive ref-counting semantics, (cf. D3237530), I am redefining `HHWheelTimer::SharedPtr`. It is now a true `std::shared_ptr`. This will break clients that attempt the following:

  HHWheelTimer::UniquePtr timer1{HHWheelTimer::newTimer()};
  HHWheelTimer::SharedPtr timer2{timer1};

In the past, that code would compile, because `timer2` could use the intrusive ref-counting, and `timer1` would still be valid. After this change, the second timer would need to be initialized with `std::move(timer1)` instead. The `UniquePtr` is starting to actually be unique.

There is only one place in the code that actually tries to do such a copy. It's in a test, which I have changed. Any other instances of that behavior would create a compilation error, so it's impossible for one to be overlooked.

Reviewed By: djwatson

Differential Revision: D3337038

fbshipit-source-id: 085e4da41c9a142d253a1ac0b1dd0fc508dff704
parent 0558fb60
...@@ -61,7 +61,7 @@ class HHWheelTimer : private folly::AsyncTimeout, ...@@ -61,7 +61,7 @@ class HHWheelTimer : private folly::AsyncTimeout,
public: public:
// This type has always been a misnomer, because it is not a unique pointer. // This type has always been a misnomer, because it is not a unique pointer.
using UniquePtr = std::unique_ptr<HHWheelTimer, Destructor>; using UniquePtr = std::unique_ptr<HHWheelTimer, Destructor>;
using SharedPtr = IntrusivePtr<HHWheelTimer>; using SharedPtr = std::shared_ptr<HHWheelTimer>;
template <typename... Args> template <typename... Args>
static UniquePtr newTimer(Args&&... args) { static UniquePtr newTimer(Args&&... args) {
......
...@@ -453,7 +453,7 @@ TEST_F(HHWheelTimerTest, cancelAll) { ...@@ -453,7 +453,7 @@ TEST_F(HHWheelTimerTest, cancelAll) {
EXPECT_EQ(1, tt.canceledTimestamps.size()); EXPECT_EQ(1, tt.canceledTimestamps.size());
} }
TEST_F(HHWheelTimerTest, SharedPtr) { TEST_F(HHWheelTimerTest, IntrusivePtr) {
HHWheelTimer::UniquePtr t( HHWheelTimer::UniquePtr t(
HHWheelTimer::newTimer(&eventBase, milliseconds(1))); HHWheelTimer::newTimer(&eventBase, milliseconds(1)));
...@@ -466,7 +466,7 @@ TEST_F(HHWheelTimerTest, SharedPtr) { ...@@ -466,7 +466,7 @@ TEST_F(HHWheelTimerTest, SharedPtr) {
t->scheduleTimeout(&t1, milliseconds(5)); t->scheduleTimeout(&t1, milliseconds(5));
t->scheduleTimeout(&t2, milliseconds(5)); t->scheduleTimeout(&t2, milliseconds(5));
HHWheelTimer::SharedPtr s(t); DelayedDestruction::IntrusivePtr<HHWheelTimer> s(t);
s->scheduleTimeout(&t3, milliseconds(10)); s->scheduleTimeout(&t3, milliseconds(10));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment