blob: 74039718f62de96890aeee3c6e6524766523a1c0 [file] [log] [blame]
[email protected]399ed422012-12-27 19:58:001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_SEQUENCE_CHECKER_IMPL_H_
6#define BASE_SEQUENCE_CHECKER_IMPL_H_
7
8#include "base/base_export.h"
fdorayeed5fa72016-07-26 22:28:459#include "base/compiler_specific.h"
avi9b6f42932015-12-26 22:15:1410#include "base/macros.h"
gcasto72c70c92017-02-14 18:06:0011#include "base/sequence_token.h"
[email protected]399ed422012-12-27 19:58:0012#include "base/synchronization/lock.h"
gcasto72c70c92017-02-14 18:06:0013#include "base/threading/sequenced_worker_pool.h"
14#include "base/threading/thread_checker_impl.h"
[email protected]399ed422012-12-27 19:58:0015
16namespace base {
17
fdorayeed5fa72016-07-26 22:28:4518// Real implementation of SequenceChecker for use in debug mode or for temporary
19// use in release mode (e.g. to CHECK on a threading issue seen only in the
20// wild).
21//
22// Note: You should almost always use the SequenceChecker class to get the right
23// version for your build configuration.
[email protected]399ed422012-12-27 19:58:0024class BASE_EXPORT SequenceCheckerImpl {
25 public:
[email protected]d52426c2013-07-30 19:26:4026 SequenceCheckerImpl();
[email protected]399ed422012-12-27 19:58:0027 ~SequenceCheckerImpl();
28
fdorayeed5fa72016-07-26 22:28:4529 // Returns true if called in sequence with previous calls to this method and
30 // the constructor.
fdoraye2b19a12016-07-29 02:30:1631 bool CalledOnValidSequence() const WARN_UNUSED_RESULT;
[email protected]399ed422012-12-27 19:58:0032
fdorayeed5fa72016-07-26 22:28:4533 // Unbinds the checker from the currently associated sequence. The checker
fdoraye2b19a12016-07-29 02:30:1634 // will be re-bound on the next call to CalledOnValidSequence().
[email protected]d52426c2013-07-30 19:26:4035 void DetachFromSequence();
[email protected]399ed422012-12-27 19:58:0036
37 private:
gcasto72c70c92017-02-14 18:06:0038 void EnsureSequenceTokenAssigned() const;
[email protected]d52426c2013-07-30 19:26:4039
[email protected]399ed422012-12-27 19:58:0040 // Guards all variables below.
41 mutable Lock lock_;
gcasto72c70c92017-02-14 18:06:0042
43 // True when the SequenceChecker is bound to a sequence or a thread.
44 mutable bool is_assigned_ = false;
45
46 mutable SequenceToken sequence_token_;
47
48 // TODO(gab): Remove this when SequencedWorkerPool is deprecated in favor of
49 // TaskScheduler. crbug.com/622400
50 mutable SequencedWorkerPool::SequenceToken sequenced_worker_pool_token_;
51
52 // Used when |sequenced_worker_pool_token_| and |sequence_token_| are invalid.
53 ThreadCheckerImpl thread_checker_;
[email protected]399ed422012-12-27 19:58:0054
55 DISALLOW_COPY_AND_ASSIGN(SequenceCheckerImpl);
56};
57
58} // namespace base
59
60#endif // BASE_SEQUENCE_CHECKER_IMPL_H_