diff options
author | timurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 17:37:01 +0000 |
---|---|---|
committer | timurrrr@chromium.org <timurrrr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-04 17:37:01 +0000 |
commit | e83ce1e3f2fcacb3d400287d78567d22a2a06cae (patch) | |
tree | 109affdb24aa780359ea8d58da9d4af07dfa5f9f /chrome/browser/cancelable_request.h | |
parent | 183a50dfa9ff9fb985560d274fac713738e3c49e (diff) | |
download | chromium_src-e83ce1e3f2fcacb3d400287d78567d22a2a06cae.zip chromium_src-e83ce1e3f2fcacb3d400287d78567d22a2a06cae.tar.gz chromium_src-e83ce1e3f2fcacb3d400287d78567d22a2a06cae.tar.bz2 |
Fix a couple of data races on booleans
BUG=21468,22520
For the explanation why these are data races,
see http://code.google.com/p/data-race-test/wiki/PopularDataRaces
Review URL: http://codereview.chromium.org/251027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cancelable_request.h')
-rw-r--r-- | chrome/browser/cancelable_request.h | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/chrome/browser/cancelable_request.h b/chrome/browser/cancelable_request.h index e83dd0c..f771d02 100644 --- a/chrome/browser/cancelable_request.h +++ b/chrome/browser/cancelable_request.h @@ -87,6 +87,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/cancellation_flag.h" #include "base/lock.h" #include "base/logging.h" #include "base/message_loop.h" @@ -365,8 +366,7 @@ class CancelableRequestBase CancelableRequestBase() : provider_(NULL), consumer_(NULL), - handle_(0), - canceled_(false) { + handle_(0) { callback_thread_ = MessageLoop::current(); } @@ -380,11 +380,12 @@ class CancelableRequestBase // The canceled flag indicates that the request should not be executed. // A request can never be uncanceled, so only a setter for true is provided. + // This can be called multiple times, but only from one thread. void set_canceled() { - canceled_ = true; + canceled_.Set(); } bool canceled() { - return canceled_; + return canceled_.IsSet(); } protected: @@ -417,7 +418,7 @@ class CancelableRequestBase CancelableRequestProvider* provider_; // Notified after we execute that the request is complete. This should only - // be accessed if !canceled_, otherwise the pointer is invalid. + // be accessed if !canceled_.IsSet(), otherwise the pointer is invalid. CancelableRequestConsumerBase* consumer_; // The handle to this request inside the provider. This will be initialized @@ -427,7 +428,7 @@ class CancelableRequestBase // Set if the caller cancels this request. No callbacks should be made when // this is set. - bool canceled_; + base::CancellationFlag canceled_; private: DISALLOW_EVIL_CONSTRUCTORS(CancelableRequestBase); @@ -512,7 +513,7 @@ class CancelableRequest : public CancelableRequestBase { // Executes the callback and notifies the provider and the consumer that this // request has been completed. This must be called on the callback_thread_. void ExecuteCallback(const TupleType& param) { - if (!canceled_) { + if (!canceled_.IsSet()) { // Execute the callback. callback_->RunWithParams(param); @@ -522,8 +523,8 @@ class CancelableRequest : public CancelableRequestBase { } } - // This should only be executed if !canceled_, otherwise the pointers may be - // invalid. + // This should only be executed if !canceled_.IsSet(), + // otherwise the pointers may be invalid. scoped_ptr<CallbackType> callback_; }; |