+ EXPECT_EQ(11, Widget::totalVal_);
+ }
+ EXPECT_EQ(11, Widget::totalVal_);
+}
+
+TEST(ThreadLocalPtr, CustomDeleterOwnershipTransfer) {
+ Widget::totalVal_ = 0;
+ {
+ ThreadLocalPtr<Widget> w;
+ auto deleter = [](Widget* ptr) {
+ Widget::customDeleter(ptr, TLPDestructionMode::THIS_THREAD);
+ };
+ std::unique_ptr<Widget, decltype(deleter)> source(new Widget(), deleter);
+ std::thread([&w, &source]() {
+ w.reset(std::move(source));
+ w.get()->val_ += 10;
+ }).join();
+ EXPECT_EQ(11, Widget::totalVal_);
+ }
+ EXPECT_EQ(11, Widget::totalVal_);
+}
+
+TEST(ThreadLocalPtr, DefaultDeleterOwnershipTransfer) {
+ Widget::totalVal_ = 0;
+ {
+ ThreadLocalPtr<Widget> w;
+ auto source = folly::make_unique<Widget>();
+ std::thread([&w, &source]() {
+ w.reset(std::move(source));
+ w.get()->val_ += 10;
+ }).join();