Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
michael@0 | 2 | // Use of this source code is governed by a BSD-style license that can be |
michael@0 | 3 | // found in the LICENSE file. |
michael@0 | 4 | |
michael@0 | 5 | #ifndef BASE_SEQUENCE_CHECKER_IMPL_H_ |
michael@0 | 6 | #define BASE_SEQUENCE_CHECKER_IMPL_H_ |
michael@0 | 7 | |
michael@0 | 8 | #include "base/base_export.h" |
michael@0 | 9 | #include "base/basictypes.h" |
michael@0 | 10 | #include "base/synchronization/lock.h" |
michael@0 | 11 | #include "base/threading/sequenced_worker_pool.h" |
michael@0 | 12 | #include "base/threading/thread_checker_impl.h" |
michael@0 | 13 | |
michael@0 | 14 | namespace base { |
michael@0 | 15 | |
michael@0 | 16 | // SequenceCheckerImpl is used to help verify that some methods of a |
michael@0 | 17 | // class are called in sequence -- that is, called from the same |
michael@0 | 18 | // SequencedTaskRunner. It is a generalization of ThreadChecker; in |
michael@0 | 19 | // particular, it behaves exactly like ThreadChecker if constructed |
michael@0 | 20 | // on a thread that is not part of a SequencedWorkerPool. |
michael@0 | 21 | class BASE_EXPORT SequenceCheckerImpl { |
michael@0 | 22 | public: |
michael@0 | 23 | SequenceCheckerImpl(); |
michael@0 | 24 | ~SequenceCheckerImpl(); |
michael@0 | 25 | |
michael@0 | 26 | // Returns whether the we are being called on the same sequence token |
michael@0 | 27 | // as previous calls. If there is no associated sequence, then returns |
michael@0 | 28 | // whether we are being called on the underlying ThreadChecker's thread. |
michael@0 | 29 | bool CalledOnValidSequencedThread() const; |
michael@0 | 30 | |
michael@0 | 31 | // Unbinds the checker from the currently associated sequence. The |
michael@0 | 32 | // checker will be re-bound on the next call to CalledOnValidSequence(). |
michael@0 | 33 | void DetachFromSequence(); |
michael@0 | 34 | |
michael@0 | 35 | private: |
michael@0 | 36 | void EnsureSequenceTokenAssigned() const; |
michael@0 | 37 | |
michael@0 | 38 | // Guards all variables below. |
michael@0 | 39 | mutable Lock lock_; |
michael@0 | 40 | |
michael@0 | 41 | // Used if |sequence_token_| is not valid. |
michael@0 | 42 | ThreadCheckerImpl thread_checker_; |
michael@0 | 43 | mutable bool sequence_token_assigned_; |
michael@0 | 44 | |
michael@0 | 45 | mutable SequencedWorkerPool::SequenceToken sequence_token_; |
michael@0 | 46 | |
michael@0 | 47 | DISALLOW_COPY_AND_ASSIGN(SequenceCheckerImpl); |
michael@0 | 48 | }; |
michael@0 | 49 | |
michael@0 | 50 | } // namespace base |
michael@0 | 51 | |
michael@0 | 52 | #endif // BASE_SEQUENCE_CHECKER_IMPL_H_ |