| 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 <memory> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/location.h" | 11 #include "base/location.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "cc/base/cc_export.h" | 16 #include "cc/base/cc_export.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 // This class wraps a SingleThreadTaskRunner but allows posted tasks to be | 20 // This class wraps a SingleThreadTaskRunner but allows posted tasks to be |
| 21 // run without a round trip through the message loop. This shortcutting | 21 // run without a round trip through the message loop. This shortcutting |
| 22 // removes guarantees about ordering. Tasks posted while the | 22 // removes guarantees about ordering. Tasks posted while the |
| (...skipping 18 matching lines...) Expand all Loading... |
| 41 // immediately. | 41 // immediately. |
| 42 // | 42 // |
| 43 // Beware of re-entrancy, make sure the CapturePostTasks object is destroyed at | 43 // Beware of re-entrancy, make sure the CapturePostTasks object is destroyed at |
| 44 // a time when it makes sense for the embedder to call arbitrary things. | 44 // a time when it makes sense for the embedder to call arbitrary things. |
| 45 class CC_EXPORT BlockingTaskRunner { | 45 class CC_EXPORT BlockingTaskRunner { |
| 46 public: | 46 public: |
| 47 // Creates a BlockingTaskRunner for a given SingleThreadTaskRunner. | 47 // Creates a BlockingTaskRunner for a given SingleThreadTaskRunner. |
| 48 // |task_runner| will be used to run the tasks which are posted while we are | 48 // |task_runner| will be used to run the tasks which are posted while we are |
| 49 // not capturing. |task_runner| should belong to same the thread on which | 49 // not capturing. |task_runner| should belong to same the thread on which |
| 50 // capturing is done. | 50 // capturing is done. |
| 51 static scoped_ptr<BlockingTaskRunner> Create( | 51 static std::unique_ptr<BlockingTaskRunner> Create( |
| 52 scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 52 scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
| 53 | 53 |
| 54 ~BlockingTaskRunner(); | 54 ~BlockingTaskRunner(); |
| 55 | 55 |
| 56 // While an object of this type is held alive on a thread, any tasks | 56 // While an object of this type is held alive on a thread, any tasks |
| 57 // posted to the thread will be captured and run as soon as the object | 57 // posted to the thread will be captured and run as soon as the object |
| 58 // is destroyed, shortcutting past the task runner. | 58 // is destroyed, shortcutting past the task runner. |
| 59 class CC_EXPORT CapturePostTasks { | 59 class CC_EXPORT CapturePostTasks { |
| 60 public: | 60 public: |
| 61 explicit CapturePostTasks(BlockingTaskRunner* blocking_runner); | 61 explicit CapturePostTasks(BlockingTaskRunner* blocking_runner); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 90 base::Lock lock_; | 90 base::Lock lock_; |
| 91 int capture_; | 91 int capture_; |
| 92 std::vector<base::Closure> captured_tasks_; | 92 std::vector<base::Closure> captured_tasks_; |
| 93 | 93 |
| 94 DISALLOW_COPY_AND_ASSIGN(BlockingTaskRunner); | 94 DISALLOW_COPY_AND_ASSIGN(BlockingTaskRunner); |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 } // namespace cc | 97 } // namespace cc |
| 98 | 98 |
| 99 #endif // CC_TREES_BLOCKING_TASK_RUNNER_H_ | 99 #endif // CC_TREES_BLOCKING_TASK_RUNNER_H_ |
| OLD | NEW |