Commit ca1e1523 authored by Andrew McFague's avatar Andrew McFague Committed by Facebook GitHub Bot

folly: Backout changes to folly::DelayedInit and pass in a reference via folly::ConcurrentLazy

Summary: This violates some expectations for how this function should be called, so explicitly allow this to be passed as a reference.

Reviewed By: yfeldblum

Differential Revision: D26215425

fbshipit-source-id: 29cff0407ec10ab61970d32da083110d1b609fbb
parent 57c897d3
...@@ -54,10 +54,10 @@ struct ConcurrentLazy { ...@@ -54,10 +54,10 @@ struct ConcurrentLazy {
explicit ConcurrentLazy(const Func& f) : func_(f) {} explicit ConcurrentLazy(const Func& f) : func_(f) {}
const result_type& operator()() const { const result_type& operator()() const {
return value_.try_emplace_with(func_); return value_.try_emplace_with(std::ref(func_));
} }
result_type& operator()() { return value_.try_emplace_with(func_); } result_type& operator()() { return value_.try_emplace_with(std::ref(func_)); }
private: private:
folly::DelayedInit<result_type> value_; folly::DelayedInit<result_type> value_;
......
...@@ -80,7 +80,7 @@ struct DelayedInit { ...@@ -80,7 +80,7 @@ struct DelayedInit {
* then the provided function is not called. * then the provided function is not called.
*/ */
template <typename Func> template <typename Func>
T& try_emplace_with(Func&& func) const { T& try_emplace_with(Func func) const {
call_once(storage_.init, [&]() mutable { call_once(storage_.init, [&]() mutable {
new (std::addressof(storage_.value)) T(func()); new (std::addressof(storage_.value)) T(func());
}); });
......
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