Chromium Code Reviews| Index: chromecast/public/task_runner.h |
| diff --git a/chromecast/public/task_runner.h b/chromecast/public/task_runner.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..404aa9cff264f9fad2c4aa8dccd153800db3bef1 |
| --- /dev/null |
| +++ b/chromecast/public/task_runner.h |
| @@ -0,0 +1,39 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROMECAST_PUBLIC_TASK_RUNNER_H_ |
| +#define CHROMECAST_PUBLIC_TASK_RUNNER_H_ |
| + |
| +#include <stdint.h> |
| + |
| +namespace chromecast { |
| + |
| +// Provides a way for vendor libraries to run code on a specific thread. |
| +// For example, cast_shell supplies an implementation of this interface through |
| +// media APIs (see MediaPipelineDeviceParams) to allow media backends to |
| +// schedule tasks to be run on the media thread. |
| +class TaskRunner { |
| + public: |
| + // Subclass and implement 'Run' to supply code to be run by PostTask or |
| + // PostDelayedTask. They both take ownership of the Task object passed in |
| + // and will delete after running the Task. |
| + class Task { |
| + public: |
| + virtual ~Task() {} |
| + virtual void Run() = 0; |
| + }; |
| + |
| + virtual ~TaskRunner() {} |
| + |
| + // Returns true if currently on the thread tied to this TaskRunner. |
| + virtual bool BelongsToCurrentThread() = 0; |
|
byungchul
2015/07/29 20:32:23
Is it necessary?
halliwell
2015/07/29 22:39:27
It's useful, and used: for the standard "if (!belo
byungchul
2015/07/29 23:12:30
Shouldn't the pattern, "if (!belongs to current th
halliwell
2015/07/30 00:19:57
That's fair. I removed it from the API here. Tas
|
| + |
| + // Posts a task to the thread's task queue. Delay of 0 does not necessarily |
| + // mean the task will run immediately, just as soon as it can be. |
| + virtual bool PostTask(Task* task, uint64_t delay_milliseconds) = 0; |
| +}; |
| + |
| +} // namespace chromecast |
| + |
| +#endif // CHROMECAST_PUBLIC_TASK_RUNNER_H_ |