OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009-2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2009-2010 Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 71 matching lines...) Loading... |
82 // | 82 // |
83 // Deep copies by threadSafeBind(): | 83 // Deep copies by threadSafeBind(): |
84 // |p0|, |p1|, ..., |pn| are processed by threadSafeBind() and thus | 84 // |p0|, |p1|, ..., |pn| are processed by threadSafeBind() and thus |
85 // CrossThreadCopier. | 85 // CrossThreadCopier. |
86 // You don't have to call manually e.g. isolatedCopy(). | 86 // You don't have to call manually e.g. isolatedCopy(). |
87 // To pass things that cannot be copied by CrossThreadCopier | 87 // To pass things that cannot be copied by CrossThreadCopier |
88 // (e.g. pointers), use AllowCrossThreadAccess() explicitly. | 88 // (e.g. pointers), use AllowCrossThreadAccess() explicitly. |
89 // |ptr| is assumed safe to be passed across threads, and | 89 // |ptr| is assumed safe to be passed across threads, and |
90 // AllowCrossThreadAccess() is applied automatically. | 90 // AllowCrossThreadAccess() is applied automatically. |
91 | 91 |
92 namespace internal { | |
93 | |
94 class CallClosureWithExecutionContextTask final : public CallClosureTaskBase<voi
d(ExecutionContext*)> { | |
95 public: | |
96 // Do not use |create| other than in createCrossThreadTask and | |
97 // createSameThreadTask. | |
98 // See http://crbug.com/390851 | |
99 static PassOwnPtr<CallClosureWithExecutionContextTask> create(PassOwnPtr<Fun
ction<void(ExecutionContext*)>> closure, bool isSameThread = false) | |
100 { | |
101 return adoptPtr(new CallClosureWithExecutionContextTask(closure, isSameT
hread)); | |
102 } | |
103 | |
104 void performTask(ExecutionContext* context) override | |
105 { | |
106 checkThread(); | |
107 (*m_closure)(context); | |
108 } | |
109 | |
110 private: | |
111 CallClosureWithExecutionContextTask(PassOwnPtr<Function<void(ExecutionContex
t*)>> closure, bool isSameThread) | |
112 : CallClosureTaskBase<void(ExecutionContext*)>(closure, isSameThread) | |
113 { | |
114 } | |
115 }; | |
116 | |
117 } // namespace internal | |
118 | |
119 // RETTYPE, PS, and MPS are added as template parameters to circumvent MSVC 18.0
0.21005.1 (VS 2013) issues. | 92 // RETTYPE, PS, and MPS are added as template parameters to circumvent MSVC 18.0
0.21005.1 (VS 2013) issues. |
120 | 93 |
121 // [1] createCrossThreadTask() for non-member functions (with ExecutionContext*
argument). | 94 // [1] createCrossThreadTask() for non-member functions (with ExecutionContext*
argument). |
122 // (P = <P1, ..., Pn>, MP = <MP1, ..., MPn, ExecutionContext*>) | 95 // (P = <P1, ..., Pn>, MP = <MP1, ..., MPn, ExecutionContext*>) |
123 template<typename... P, typename... MP, | 96 template<typename... P, typename... MP, |
124 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> | 97 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> |
125 typename std::enable_if<PS + 1 == MPS, RETTYPE>::type createCrossThreadTask(void
(*function)(MP...), const P&... parameters) | 98 typename std::enable_if<PS + 1 == MPS, RETTYPE>::type createCrossThreadTask(void
(*function)(MP...), const P&... parameters) |
126 { | 99 { |
127 return internal::CallClosureWithExecutionContextTask::create(threadSafeBind<
ExecutionContext*>(function, parameters...)); | 100 return internal::CallClosureWithExecutionContextTask<WTF::CrossThreadAffinit
y>::create(threadSafeBind<ExecutionContext*>(function, parameters...)); |
128 } | 101 } |
129 | 102 |
130 // [2] createCrossThreadTask() for member functions of class C (with ExecutionCo
ntext* argument) + raw pointer (C*). | 103 // [2] createCrossThreadTask() for member functions of class C (with ExecutionCo
ntext* argument) + raw pointer (C*). |
131 // (P = <P1, ..., Pn>, MP = <MP1, ..., MPn, ExecutionContext*>) | 104 // (P = <P1, ..., Pn>, MP = <MP1, ..., MPn, ExecutionContext*>) |
132 template<typename C, typename... P, typename... MP, | 105 template<typename C, typename... P, typename... MP, |
133 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> | 106 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> |
134 typename std::enable_if<PS + 1 == MPS, RETTYPE>::type createCrossThreadTask(void
(C::*function)(MP...), C* p, const P&... parameters) | 107 typename std::enable_if<PS + 1 == MPS, RETTYPE>::type createCrossThreadTask(void
(C::*function)(MP...), C* p, const P&... parameters) |
135 { | 108 { |
136 return internal::CallClosureWithExecutionContextTask::create(threadSafeBind<
ExecutionContext*>(function, AllowCrossThreadAccess(p), parameters...)); | 109 return internal::CallClosureWithExecutionContextTask<WTF::CrossThreadAffinit
y>::create(threadSafeBind<ExecutionContext*>(function, AllowCrossThreadAccess(p)
, parameters...)); |
137 } | 110 } |
138 | 111 |
139 // [3] createCrossThreadTask() for non-member functions | 112 // [3] createCrossThreadTask() for non-member functions |
140 // (P = <P1, ..., Pn>, MP = <MP1, ..., MPn>) | 113 // (P = <P1, ..., Pn>, MP = <MP1, ..., MPn>) |
141 template<typename... P, typename... MP, | 114 template<typename... P, typename... MP, |
142 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> | 115 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> |
143 typename std::enable_if<PS == MPS, RETTYPE>::type createCrossThreadTask(void (*f
unction)(MP...), const P&... parameters) | 116 typename std::enable_if<PS == MPS, RETTYPE>::type createCrossThreadTask(void (*f
unction)(MP...), const P&... parameters) |
144 { | 117 { |
145 return internal::CallClosureTask::create(threadSafeBind(function, parameters
...)); | 118 return internal::CallClosureTask<WTF::CrossThreadAffinity>::create(threadSaf
eBind(function, parameters...)); |
146 } | 119 } |
147 | 120 |
148 // [4] createCrossThreadTask() for member functions of class C + raw pointer (C*
) | 121 // [4] createCrossThreadTask() for member functions of class C + raw pointer (C*
) |
149 // [5] createCrossThreadTask() for member functions of class C + weak pointer (c
onst WeakPtr<C>&) | 122 // [5] createCrossThreadTask() for member functions of class C + weak pointer (c
onst WeakPtr<C>&) |
150 // (P = <P1, ..., Pn>, MP = <MP1, ..., MPn>) | 123 // (P = <P1, ..., Pn>, MP = <MP1, ..., MPn>) |
151 template<typename C, typename... P, typename... MP, | 124 template<typename C, typename... P, typename... MP, |
152 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> | 125 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> |
153 typename std::enable_if<PS == MPS, RETTYPE>::type createCrossThreadTask(void (C:
:*function)(MP...), C* p, const P&... parameters) | 126 typename std::enable_if<PS == MPS, RETTYPE>::type createCrossThreadTask(void (C:
:*function)(MP...), C* p, const P&... parameters) |
154 { | 127 { |
155 return internal::CallClosureTask::create(threadSafeBind(function, AllowCross
ThreadAccess(p), parameters...)); | 128 return internal::CallClosureTask<WTF::CrossThreadAffinity>::create(threadSaf
eBind(function, AllowCrossThreadAccess(p), parameters...)); |
156 } | 129 } |
157 | 130 |
158 template<typename C, typename... P, typename... MP, | 131 template<typename C, typename... P, typename... MP, |
159 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> | 132 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> |
160 typename std::enable_if<PS == MPS, RETTYPE>::type createCrossThreadTask(void (C:
:*function)(MP...), const WeakPtr<C>& p, const P&... parameters) | 133 typename std::enable_if<PS == MPS, RETTYPE>::type createCrossThreadTask(void (C:
:*function)(MP...), const WeakPtr<C>& p, const P&... parameters) |
161 { | 134 { |
162 return internal::CallClosureTask::create(threadSafeBind(function, AllowCross
ThreadAccess(p), parameters...)); | 135 return internal::CallClosureTask<WTF::CrossThreadAffinity>::create(threadSaf
eBind(function, AllowCrossThreadAccess(p), parameters...)); |
163 } | 136 } |
164 | 137 |
165 // [6] createCrossThreadTask() for member functions + pointers to class C other
than C* or const WeakPtr<C>& | 138 // [6] createCrossThreadTask() for member functions + pointers to class C other
than C* or const WeakPtr<C>& |
166 // (P = <P0, P1, ..., Pn>, MP = <MP1, ..., MPn>) | 139 // (P = <P0, P1, ..., Pn>, MP = <MP1, ..., MPn>) |
167 template<typename C, typename... P, typename... MP, | 140 template<typename C, typename... P, typename... MP, |
168 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> | 141 typename RETTYPE = PassOwnPtr<ExecutionContextTask>, size_t PS = sizeof...(P
), size_t MPS = sizeof...(MP)> |
169 typename std::enable_if<PS == MPS + 1, RETTYPE>::type createCrossThreadTask(void
(C::*function)(MP...), const P&... parameters) | 142 typename std::enable_if<PS == MPS + 1, RETTYPE>::type createCrossThreadTask(void
(C::*function)(MP...), const P&... parameters) |
170 { | 143 { |
171 return internal::CallClosureTask::create(threadSafeBind(function, parameters
...)); | 144 return internal::CallClosureTask<WTF::CrossThreadAffinity>::create(threadSaf
eBind(function, parameters...)); |
172 } | 145 } |
173 | 146 |
174 } // namespace blink | 147 } // namespace blink |
175 | 148 |
176 #endif // CrossThreadTask_h | 149 #endif // CrossThreadTask_h |
OLD | NEW |