OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "wtf/Assertions.h" | 31 #include "wtf/Assertions.h" |
32 #include "wtf/PassOwnPtr.h" | 32 #include "wtf/PassOwnPtr.h" |
33 #include "wtf/PassRefPtr.h" | 33 #include "wtf/PassRefPtr.h" |
34 #include "wtf/PtrUtil.h" | 34 #include "wtf/PtrUtil.h" |
35 #include "wtf/RefPtr.h" | 35 #include "wtf/RefPtr.h" |
36 #include "wtf/ThreadSafeRefCounted.h" | 36 #include "wtf/ThreadSafeRefCounted.h" |
37 #include "wtf/WeakPtr.h" | 37 #include "wtf/WeakPtr.h" |
38 #include <tuple> | 38 #include <tuple> |
39 #include <utility> | 39 #include <utility> |
40 | 40 |
| 41 namespace blink { |
| 42 template<typename T> class CrossThreadPersistent; |
| 43 } |
| 44 |
41 namespace WTF { | 45 namespace WTF { |
42 | 46 |
43 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object | 47 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object |
44 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. | 48 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. |
45 | 49 |
46 // Thread Safety: | 50 // Thread Safety: |
47 // | 51 // |
48 // WTF::bind() and SameThreadClosure should be used for same-thread closures | 52 // WTF::bind() and SameThreadClosure should be used for same-thread closures |
49 // only, i.e. the closures must be created, executed and destructed on | 53 // only, i.e. the closures must be created, executed and destructed on |
50 // the same thread. | 54 // the same thread. |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 }; | 229 }; |
226 | 230 |
227 template <typename T> | 231 template <typename T> |
228 struct ParamStorageTraits<PassedWrapper<T>> { | 232 struct ParamStorageTraits<PassedWrapper<T>> { |
229 typedef PassedWrapper<T> StorageType; | 233 typedef PassedWrapper<T> StorageType; |
230 | 234 |
231 static StorageType wrap(PassedWrapper<T>&& value) { return std::move(value);
} | 235 static StorageType wrap(PassedWrapper<T>&& value) { return std::move(value);
} |
232 static T unwrap(StorageType& value) { return value.moveOut(); } | 236 static T unwrap(StorageType& value) { return value.moveOut(); } |
233 }; | 237 }; |
234 | 238 |
| 239 template<typename T, bool isGarbageCollected> struct PointerParamStorageTraits; |
| 240 |
| 241 template<typename T> |
| 242 struct PointerParamStorageTraits<T*, false> { |
| 243 STATIC_ONLY(PointerParamStorageTraits); |
| 244 using StorageType = T*; |
| 245 |
| 246 static StorageType wrap(T* value) { return value; } |
| 247 static T* unwrap(const StorageType& value) { return value; } |
| 248 }; |
| 249 |
| 250 template<typename T> |
| 251 struct PointerParamStorageTraits<T*, true> { |
| 252 STATIC_ONLY(PointerParamStorageTraits); |
| 253 using StorageType = blink::CrossThreadPersistent<T>; |
| 254 |
| 255 static StorageType wrap(T* value) { return value; } |
| 256 static T* unwrap(const StorageType& value) { return value.get(); } |
| 257 }; |
| 258 |
| 259 template<typename T> |
| 260 struct ParamStorageTraits<T*> : public PointerParamStorageTraits<T*, IsGarbageCo
llectedType<T>::value> { |
| 261 STATIC_ONLY(ParamStorageTraits); |
| 262 }; |
| 263 |
235 enum FunctionThreadAffinity { | 264 enum FunctionThreadAffinity { |
236 CrossThreadAffinity, | 265 CrossThreadAffinity, |
237 SameThreadAffinity | 266 SameThreadAffinity |
238 }; | 267 }; |
239 | 268 |
240 template<typename, FunctionThreadAffinity threadAffinity = SameThreadAffinity> | 269 template<typename, FunctionThreadAffinity threadAffinity = SameThreadAffinity> |
241 class Function; | 270 class Function; |
242 | 271 |
243 template<FunctionThreadAffinity threadAffinity, typename R, typename... Args> | 272 template<FunctionThreadAffinity threadAffinity, typename R, typename... Args> |
244 class Function<R(Args...), threadAffinity> { | 273 class Function<R(Args...), threadAffinity> { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 375 |
347 } // namespace WTF | 376 } // namespace WTF |
348 | 377 |
349 using WTF::passed; | 378 using WTF::passed; |
350 using WTF::Function; | 379 using WTF::Function; |
351 using WTF::bind; | 380 using WTF::bind; |
352 using WTF::SameThreadClosure; | 381 using WTF::SameThreadClosure; |
353 using WTF::CrossThreadClosure; | 382 using WTF::CrossThreadClosure; |
354 | 383 |
355 #endif // WTF_Functional_h | 384 #endif // WTF_Functional_h |
OLD | NEW |