OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TASK_RUNNER_H_ | 5 #ifndef BASE_TASK_RUNNER_H_ |
6 #define BASE_TASK_RUNNER_H_ | 6 #define BASE_TASK_RUNNER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 | 65 |
66 // Like PostTask, but tries to run the posted task only after | 66 // Like PostTask, but tries to run the posted task only after |
67 // |delay_ms| has passed. | 67 // |delay_ms| has passed. |
68 // | 68 // |
69 // It is valid for an implementation to ignore |delay_ms|; that is, | 69 // It is valid for an implementation to ignore |delay_ms|; that is, |
70 // to have PostDelayedTask behave the same as PostTask. | 70 // to have PostDelayedTask behave the same as PostTask. |
71 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, | 71 virtual bool PostDelayedTask(const tracked_objects::Location& from_here, |
72 OnceClosure task, | 72 OnceClosure task, |
73 base::TimeDelta delay) = 0; | 73 base::TimeDelta delay) = 0; |
74 | 74 |
75 // Returns true if the current thread is a thread on which a task | 75 // Drepecated: favor RunsTasksInCurrentSequence(). |
76 // may be run, and false if no task will be run on the current | 76 // TODO(http://crbug.com/665062): mass redirect callers and remove this. |
77 // thread. | 77 inline bool RunsTasksOnCurrentThread() const { |
gab
2017/04/27 14:31:17
Don't need explicit "inline" keyword.
Per spec: "
| |
78 return RunsTasksInCurrentSequence(); | |
79 } | |
80 | |
81 // Returns true iff tasks posted to this TaskRunner are sequenced | |
82 // with this call. | |
78 // | 83 // |
79 // It is valid for an implementation to always return true, or in | 84 // In particular: |
80 // general to use 'true' as a default value. | 85 // - Returns true if this is a SequencedTaskRunner to which the |
81 virtual bool RunsTasksOnCurrentThread() const = 0; | 86 // current task was posted. |
87 // - Returns true if this is a SequencedTaskRunner bound to the | |
88 // same sequence as the SequencedTaskRunner to which the current | |
89 // task was posted. | |
90 // - Returns true if this is a SingleThreadTaskRunner bound to | |
91 // the current thread. | |
92 // TODO(http://crbug.com/665062): | |
93 // This API doesn't make sense for parallel TaskRunners. | |
94 // Introduce alternate static APIs for documentation purposes of "this runs | |
95 // in pool X", have RunsTasksInCurrentSequence() return false for parallel | |
96 // TaskRunners, and ultimately move this method down to SequencedTaskRunner. | |
97 virtual bool RunsTasksInCurrentSequence() const = 0; | |
82 | 98 |
83 // Posts |task| on the current TaskRunner. On completion, |reply| | 99 // Posts |task| on the current TaskRunner. On completion, |reply| |
84 // is posted to the thread that called PostTaskAndReply(). Both | 100 // is posted to the thread that called PostTaskAndReply(). Both |
85 // |task| and |reply| are guaranteed to be deleted on the thread | 101 // |task| and |reply| are guaranteed to be deleted on the thread |
86 // from which PostTaskAndReply() is invoked. This allows objects | 102 // from which PostTaskAndReply() is invoked. This allows objects |
87 // that must be deleted on the originating thread to be bound into | 103 // that must be deleted on the originating thread to be bound into |
88 // the |task| and |reply| Closures. In particular, it can be useful | 104 // the |task| and |reply| Closures. In particular, it can be useful |
89 // to use WeakPtr<> in the |reply| Closure so that the reply | 105 // to use WeakPtr<> in the |reply| Closure so that the reply |
90 // operation can be canceled. See the following pseudo-code: | 106 // operation can be canceled. See the following pseudo-code: |
91 // | 107 // |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 virtual void OnDestruct() const; | 157 virtual void OnDestruct() const; |
142 }; | 158 }; |
143 | 159 |
144 struct BASE_EXPORT TaskRunnerTraits { | 160 struct BASE_EXPORT TaskRunnerTraits { |
145 static void Destruct(const TaskRunner* task_runner); | 161 static void Destruct(const TaskRunner* task_runner); |
146 }; | 162 }; |
147 | 163 |
148 } // namespace base | 164 } // namespace base |
149 | 165 |
150 #endif // BASE_TASK_RUNNER_H_ | 166 #endif // BASE_TASK_RUNNER_H_ |
OLD | NEW |