Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: webrtc/base/asyncinvoker-inl.h

Issue 2726263004: Fixing race between CallbackCanceled and CancelCallback in AsyncInvoker. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_BASE_ASYNCINVOKER_INL_H_ 11 #ifndef WEBRTC_BASE_ASYNCINVOKER_INL_H_
12 #define WEBRTC_BASE_ASYNCINVOKER_INL_H_ 12 #define WEBRTC_BASE_ASYNCINVOKER_INL_H_
13 13
14 #include "webrtc/base/atomicops.h" 14 #include "webrtc/base/atomicops.h"
15 #include "webrtc/base/bind.h" 15 #include "webrtc/base/bind.h"
16 #include "webrtc/base/callback.h" 16 #include "webrtc/base/callback.h"
17 #include "webrtc/base/criticalsection.h" 17 #include "webrtc/base/criticalsection.h"
18 #include "webrtc/base/messagehandler.h" 18 #include "webrtc/base/messagehandler.h"
19 #include "webrtc/base/sigslot.h" 19 #include "webrtc/base/sigslot.h"
20 #include "webrtc/base/thread.h" 20 #include "webrtc/base/thread.h"
21 #include "webrtc/base/thread_annotations.h"
21 22
22 namespace rtc { 23 namespace rtc {
23 24
24 class AsyncInvoker; 25 class AsyncInvoker;
25 26
26 // Helper class for AsyncInvoker. Runs a task and triggers a callback 27 // Helper class for AsyncInvoker. Runs a task and triggers a callback
27 // on the calling thread if necessary. 28 // on the calling thread if necessary.
28 class AsyncClosure { 29 class AsyncClosure {
29 public: 30 public:
30 explicit AsyncClosure(AsyncInvoker* invoker) : invoker_(invoker) {} 31 explicit AsyncClosure(AsyncInvoker* invoker) : invoker_(invoker) {}
(...skipping 30 matching lines...) Expand all
61 62
62 protected: 63 protected:
63 NotifyingAsyncClosureBase(AsyncInvoker* invoker, 64 NotifyingAsyncClosureBase(AsyncInvoker* invoker,
64 const Location& callback_posted_from, 65 const Location& callback_posted_from,
65 Thread* calling_thread); 66 Thread* calling_thread);
66 void TriggerCallback(); 67 void TriggerCallback();
67 void SetCallback(const Callback0<void>& callback) { 68 void SetCallback(const Callback0<void>& callback) {
68 CritScope cs(&crit_); 69 CritScope cs(&crit_);
69 callback_ = callback; 70 callback_ = callback;
70 } 71 }
71 bool CallbackCanceled() const { return calling_thread_ == nullptr; } 72 bool CallbackCanceled() const {
73 CritScope cs(&crit_);
74 return calling_thread_ == nullptr;
75 }
72 76
73 private: 77 private:
74 Location callback_posted_from_; 78 Location callback_posted_from_;
75 Callback0<void> callback_;
76 CriticalSection crit_; 79 CriticalSection crit_;
77 Thread* calling_thread_; 80 Callback0<void> callback_ GUARDED_BY(crit_);
81 Thread* calling_thread_ GUARDED_BY(crit_);
78 82
79 void CancelCallback(); 83 void CancelCallback();
80 }; 84 };
81 85
82 // Closures that have a non-void return value and require a callback. 86 // Closures that have a non-void return value and require a callback.
83 template <class ReturnT, class FunctorT, class HostT> 87 template <class ReturnT, class FunctorT, class HostT>
84 class NotifyingAsyncClosure : public NotifyingAsyncClosureBase { 88 class NotifyingAsyncClosure : public NotifyingAsyncClosureBase {
85 public: 89 public:
86 NotifyingAsyncClosure(AsyncInvoker* invoker, 90 NotifyingAsyncClosure(AsyncInvoker* invoker,
87 const Location& callback_posted_from, 91 const Location& callback_posted_from,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 TriggerCallback(); 135 TriggerCallback();
132 } 136 }
133 137
134 private: 138 private:
135 FunctorT functor_; 139 FunctorT functor_;
136 }; 140 };
137 141
138 } // namespace rtc 142 } // namespace rtc
139 143
140 #endif // WEBRTC_BASE_ASYNCINVOKER_INL_H_ 144 #endif // WEBRTC_BASE_ASYNCINVOKER_INL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698