Chromium Code Reviews| Index: third_party/WebKit/Source/wtf/Functional.h |
| diff --git a/third_party/WebKit/Source/wtf/Functional.h b/third_party/WebKit/Source/wtf/Functional.h |
| index b0ff0cccd3b82f97ace0f236c00f41478a3781ee..9c4b77800cd46d981ca632c64e0815bc16c0c6b5 100644 |
| --- a/third_party/WebKit/Source/wtf/Functional.h |
| +++ b/third_party/WebKit/Source/wtf/Functional.h |
| @@ -93,6 +93,11 @@ namespace WTF { |
| // Obviously, if you create a functor this way, you shouldn't call the functor twice or more; after the second call, |
| // the passed argument may be invalid. |
| +enum FunctionThreadAffinity { |
| + CrossThreadAffinity, |
| + SameThreadAffinity |
| +}; |
| + |
| template <typename T> |
| class PassedWrapper final { |
| public: |
| @@ -113,6 +118,30 @@ PassedWrapper<T> passed(T&& value) |
| return PassedWrapper<T>(std::move(value)); |
| } |
| +template <typename T, FunctionThreadAffinity threadAffinity> |
| +class UnretainedWrapper final { |
| +public: |
| + explicit UnretainedWrapper(T* ptr) : m_ptr(ptr) { } |
| + T* value() const { return m_ptr; } |
| + |
| +private: |
| + T* m_ptr; |
| +}; |
| + |
| +template <typename T> |
| +UnretainedWrapper<T, SameThreadAffinity> unretained(T* value) |
| +{ |
| + static_assert(!WTF::IsGarbageCollectedType<T>::value, "unretained() + GCed type is forbidden"); |
| + return UnretainedWrapper<T, SameThreadAffinity>(value); |
| +} |
| + |
| +template <typename T> |
| +UnretainedWrapper<T, CrossThreadAffinity> crossThreadUnretained(T* value) |
| +{ |
| + static_assert(!WTF::IsGarbageCollectedType<T>::value, "crossThreadUnretained() + GCed type is forbidden"); |
| + return UnretainedWrapper<T, CrossThreadAffinity>(value); |
| +} |
| + |
| // A FunctionWrapper is a class template that can wrap a function pointer or a member function pointer and |
| // provide a unified interface for calling that function. |
| template <typename> |
| @@ -229,9 +258,12 @@ struct ParamStorageTraits<PassedWrapper<T>> { |
| static T unwrap(StorageType& value) { return value.moveOut(); } |
| }; |
| -enum FunctionThreadAffinity { |
| - CrossThreadAffinity, |
| - SameThreadAffinity |
| +template <typename T, FunctionThreadAffinity threadAffinity> |
| +struct ParamStorageTraits<UnretainedWrapper<T, threadAffinity>> { |
| + typedef UnretainedWrapper<T, threadAffinity> StorageType; |
| + |
| + static StorageType wrap(UnretainedWrapper<T, threadAffinity>&& value) { return std::move(value); } |
|
Yuta Kitamura
2016/05/17 09:37:04
rvalue reference + std::move() sounds like an over
hiroshige
2016/06/09 09:21:53
Done.
|
| + static T* unwrap(const StorageType& value) { return value.value(); } |
| }; |
| template<typename, FunctionThreadAffinity threadAffinity = SameThreadAffinity> |
| @@ -344,6 +376,8 @@ typedef Function<void(), CrossThreadAffinity> CrossThreadClosure; |
| } // namespace WTF |
| using WTF::passed; |
| +using WTF::unretained; |
| +using WTF::crossThreadUnretained; |
| using WTF::Function; |
| using WTF::bind; |
| using WTF::SameThreadClosure; |