| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CC_TREES_BLOCKING_TASK_RUNNER_H_ | 5 #ifndef CC_TREES_BLOCKING_TASK_RUNNER_H_ |
| 6 #define CC_TREES_BLOCKING_TASK_RUNNER_H_ | 6 #define CC_TREES_BLOCKING_TASK_RUNNER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/threading/platform_thread.h" |
| 14 #include "cc/base/cc_export.h" | 15 #include "cc/base/cc_export.h" |
| 15 | 16 |
| 16 namespace cc { | 17 namespace cc { |
| 17 | 18 |
| 18 // This class wraps a SingleThreadTaskRunner but allows posted tasks to be | 19 // This class wraps a SingleThreadTaskRunner but allows posted tasks to be |
| 19 // run without a round trip through the message loop. This shortcutting | 20 // run without a round trip through the message loop. This shortcutting |
| 20 // removes guarantees about ordering. Tasks posted while the | 21 // removes guarantees about ordering. Tasks posted while the |
| 21 // BlockingTaskRunner is in a capturing state will run in order, and tasks | 22 // BlockingTaskRunner is in a capturing state will run in order, and tasks |
| 22 // posted while the BlockingTaskRunner is /not/ in a capturing state will | 23 // posted while the BlockingTaskRunner is /not/ in a capturing state will |
| 23 // run in order, but the two sets of tasks will *not* run in order relative | 24 // run in order, but the two sets of tasks will *not* run in order relative |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 ~CapturePostTasks(); | 56 ~CapturePostTasks(); |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 scoped_refptr<BlockingTaskRunner> blocking_runner_; | 59 scoped_refptr<BlockingTaskRunner> blocking_runner_; |
| 59 | 60 |
| 60 DISALLOW_COPY_AND_ASSIGN(CapturePostTasks); | 61 DISALLOW_COPY_AND_ASSIGN(CapturePostTasks); |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 // True if tasks posted to the BlockingTaskRunner will run on the current | 64 // True if tasks posted to the BlockingTaskRunner will run on the current |
| 64 // thread. | 65 // thread. |
| 65 bool BelongsToCurrentThread() { | 66 bool BelongsToCurrentThread(); |
| 66 return task_runner_->BelongsToCurrentThread(); | |
| 67 } | |
| 68 | 67 |
| 69 // Posts a task using the contained SingleThreadTaskRunner unless |capture_| | 68 // Posts a task using the contained SingleThreadTaskRunner unless |capture_| |
| 70 // is true. When |capture_| is true, tasks posted will be caught and stored | 69 // is true. When |capture_| is true, tasks posted will be caught and stored |
| 71 // until the capturing stops. At that time the tasks will be run directly | 70 // until the capturing stops. At that time the tasks will be run directly |
| 72 // instead of being posted to the SingleThreadTaskRunner. | 71 // instead of being posted to the SingleThreadTaskRunner. |
| 73 bool PostTask(const tracked_objects::Location& from_here, | 72 bool PostTask(const tracked_objects::Location& from_here, |
| 74 const base::Closure& task); | 73 const base::Closure& task); |
| 75 | 74 |
| 76 private: | 75 private: |
| 77 friend class base::RefCountedThreadSafe<BlockingTaskRunner>; | 76 friend class base::RefCountedThreadSafe<BlockingTaskRunner>; |
| 78 | 77 |
| 79 explicit BlockingTaskRunner( | 78 explicit BlockingTaskRunner( |
| 80 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 79 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 81 virtual ~BlockingTaskRunner(); | 80 virtual ~BlockingTaskRunner(); |
| 82 | 81 |
| 83 void SetCapture(bool capture); | 82 void SetCapture(bool capture); |
| 84 | 83 |
| 84 base::PlatformThreadId thread_id_; |
| 85 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 85 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 86 | 86 |
| 87 base::Lock lock_; | 87 base::Lock lock_; |
| 88 int capture_; | 88 int capture_; |
| 89 std::vector<base::Closure> captured_tasks_; | 89 std::vector<base::Closure> captured_tasks_; |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 } // namespace cc | 92 } // namespace cc |
| 93 | 93 |
| 94 #endif // CC_TREES_BLOCKING_TASK_RUNNER_H_ | 94 #endif // CC_TREES_BLOCKING_TASK_RUNNER_H_ |
| OLD | NEW |