OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 CHROMECAST_PUBLIC_TASK_RUNNER_H_ | |
6 #define CHROMECAST_PUBLIC_TASK_RUNNER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 namespace chromecast { | |
11 | |
12 // Provides a way for vendor libraries to run code on a specific thread. | |
13 // For example, cast_shell supplies an implementation of this interface through | |
14 // media APIs (see MediaPipelineDeviceParams) to allow media backends to | |
15 // schedule tasks to be run on the media thread. | |
16 class TaskRunner { | |
17 public: | |
18 // Subclass and implement 'Run' to supply code to be run by PostTask or | |
19 // PostDelayedTask. They both take ownership of the Task object passed in | |
20 // and will delete after running the Task. | |
21 class Task { | |
22 public: | |
23 virtual ~Task() {} | |
24 virtual void Run() = 0; | |
25 }; | |
26 | |
27 virtual ~TaskRunner() {} | |
28 | |
29 // Returns true if currently on the thread tied to this TaskRunner. | |
30 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
| |
31 | |
32 // Posts a task to the thread's task queue. Delay of 0 does not necessarily | |
33 // mean the task will run immediately, just as soon as it can be. | |
34 virtual bool PostTask(Task* task, uint64_t delay_milliseconds) = 0; | |
35 }; | |
36 | |
37 } // namespace chromecast | |
38 | |
39 #endif // CHROMECAST_PUBLIC_TASK_RUNNER_H_ | |
OLD | NEW |