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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 } | 53 } |
54 | 54 |
55 namespace WTF { | 55 namespace WTF { |
56 | 56 |
57 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object | 57 // Functional.h provides a very simple way to bind a function pointer and argume
nts together into a function object |
58 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. | 58 // that can be stored, copied and invoked, similar to how boost::bind and std::b
ind in C++11. |
59 | 59 |
60 // Thread Safety: | 60 // Thread Safety: |
61 // | 61 // |
62 // WTF::bind() and SameThreadClosure should be used for same-thread closures | 62 // WTF::bind() and WTF::Closure should be used for same-thread closures |
63 // only, i.e. the closures must be created, executed and destructed on | 63 // only, i.e. the closures must be created, executed and destructed on |
64 // the same thread. | 64 // the same thread. |
65 // Use crossThreadBind() and CrossThreadClosure if the function/task is called | 65 // Use crossThreadBind() and CrossThreadClosure if the function/task is called |
66 // or destructed on a (potentially) different thread from the current thread. | 66 // or destructed on a (potentially) different thread from the current thread. |
67 | 67 |
68 // WTF::bind() and move semantics | 68 // WTF::bind() and move semantics |
69 // ============================== | 69 // ============================== |
70 // | 70 // |
71 // For unbound parameters (arguments supplied later on the bound functor directl
y), there are two ways to pass movable | 71 // For unbound parameters (arguments supplied later on the bound functor directl
y), there are two ways to pass movable |
72 // arguments: | 72 // arguments: |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 using UnboundRunType = base::MakeUnboundRunType<FunctionType, BoundParameter
s...>; | 255 using UnboundRunType = base::MakeUnboundRunType<FunctionType, BoundParameter
s...>; |
256 return wrapUnique(new Function<UnboundRunType, threadAffinity>(base::Bind(fu
nction, typename ParamStorageTraits<typename std::decay<BoundParameters>::type>:
:StorageType(std::forward<BoundParameters>(boundParameters))...))); | 256 return wrapUnique(new Function<UnboundRunType, threadAffinity>(base::Bind(fu
nction, typename ParamStorageTraits<typename std::decay<BoundParameters>::type>:
:StorageType(std::forward<BoundParameters>(boundParameters))...))); |
257 } | 257 } |
258 | 258 |
259 template <typename FunctionType, typename... BoundParameters> | 259 template <typename FunctionType, typename... BoundParameters> |
260 std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters.
..>, SameThreadAffinity>> bind(FunctionType function, BoundParameters&&... bound
Parameters) | 260 std::unique_ptr<Function<base::MakeUnboundRunType<FunctionType, BoundParameters.
..>, SameThreadAffinity>> bind(FunctionType function, BoundParameters&&... bound
Parameters) |
261 { | 261 { |
262 return bindInternal<SameThreadAffinity>(function, std::forward<BoundParamete
rs>(boundParameters)...); | 262 return bindInternal<SameThreadAffinity>(function, std::forward<BoundParamete
rs>(boundParameters)...); |
263 } | 263 } |
264 | 264 |
265 typedef Function<void(), SameThreadAffinity> SameThreadClosure; | 265 typedef Function<void(), SameThreadAffinity> Closure; |
266 typedef Function<void(), CrossThreadAffinity> CrossThreadClosure; | 266 typedef Function<void(), CrossThreadAffinity> CrossThreadClosure; |
267 | 267 |
268 } // namespace WTF | 268 } // namespace WTF |
269 | 269 |
270 using WTF::passed; | 270 using WTF::passed; |
271 using WTF::unretained; | 271 using WTF::unretained; |
272 using WTF::crossThreadUnretained; | 272 using WTF::crossThreadUnretained; |
273 | 273 |
274 using WTF::Function; | 274 using WTF::Function; |
275 using WTF::SameThreadClosure; | |
276 using WTF::CrossThreadClosure; | 275 using WTF::CrossThreadClosure; |
277 | 276 |
278 #endif // WTF_Functional_h | 277 #endif // WTF_Functional_h |
OLD | NEW |