| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 #ifndef WebThread_h | 25 #ifndef WebThread_h |
| 26 #define WebThread_h | 26 #define WebThread_h |
| 27 | 27 |
| 28 #include "WebCommon.h" | 28 #include "WebCommon.h" |
| 29 #include <stdint.h> | 29 #include <stdint.h> |
| 30 | 30 |
| 31 #ifdef INSIDE_BLINK | |
| 32 #include "wtf/Functional.h" | |
| 33 #endif | |
| 34 | |
| 35 namespace blink { | 31 namespace blink { |
| 36 class WebScheduler; | 32 class WebScheduler; |
| 37 class WebTaskRunner; | 33 class WebTaskRunner; |
| 38 class WebTraceLocation; | 34 class WebTraceLocation; |
| 39 | 35 |
| 40 // Always an integer value. | 36 // Always an integer value. |
| 41 typedef uintptr_t PlatformThreadId; | 37 typedef uintptr_t PlatformThreadId; |
| 42 | 38 |
| 43 // Provides an interface to an embedder-defined thread implementation. | 39 // Provides an interface to an embedder-defined thread implementation. |
| 44 // | 40 // |
| 45 // Deleting the thread blocks until all pending, non-delayed tasks have been | 41 // Deleting the thread blocks until all pending, non-delayed tasks have been |
| 46 // run. | 42 // run. |
| 47 class BLINK_PLATFORM_EXPORT WebThread { | 43 class BLINK_PLATFORM_EXPORT WebThread { |
| 48 public: | 44 public: |
| 49 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is | 45 // An IdleTask is passed a deadline in CLOCK_MONOTONIC seconds and is |
| 50 // expected to complete before this deadline. | 46 // expected to complete before this deadline. |
| 51 class IdleTask { | 47 class IdleTask { |
| 52 public: | 48 public: |
| 53 virtual ~IdleTask() { } | 49 virtual ~IdleTask() { } |
| 54 virtual void run(double deadlineSeconds) = 0; | 50 virtual void run(double deadlineSeconds) = 0; |
| 55 }; | 51 }; |
| 56 | 52 |
| 53 // TODO(alexclarke): Remove this once it's no longer referenced by chromium. |
| 57 class BLINK_PLATFORM_EXPORT Task { | 54 class BLINK_PLATFORM_EXPORT Task { |
| 58 public: | 55 public: |
| 59 virtual ~Task() { } | 56 virtual ~Task() { } |
| 60 virtual void run() = 0; | 57 virtual void run() = 0; |
| 61 }; | 58 }; |
| 62 | 59 |
| 63 class BLINK_PLATFORM_EXPORT TaskObserver { | 60 class BLINK_PLATFORM_EXPORT TaskObserver { |
| 64 public: | 61 public: |
| 65 virtual ~TaskObserver() { } | 62 virtual ~TaskObserver() { } |
| 66 virtual void willProcessTask() = 0; | 63 virtual void willProcessTask() = 0; |
| 67 virtual void didProcessTask() = 0; | 64 virtual void didProcessTask() = 0; |
| 68 }; | 65 }; |
| 69 | 66 |
| 70 // postTask() and postDelayedTask() take ownership of the passed Task | 67 // postTask() and postDelayedTask() take ownership of the passed Task |
| 71 // object. It is safe to invoke postTask() and postDelayedTask() from any | 68 // object. It is safe to invoke postTask() and postDelayedTask() from any |
| 72 // thread. | 69 // thread. |
| 73 // TODO(alexclarke): Remove postTask & postDelayedTask. | 70 // TODO(alexclarke): Remove postTask & postDelayedTask. |
| 74 virtual void postTask(const WebTraceLocation&, Task*) = 0; | 71 virtual void postTask(const WebTraceLocation&, Task*) { } |
| 75 virtual void postDelayedTask(const WebTraceLocation&, Task*, long long delay
Ms) = 0; | 72 virtual void postDelayedTask(const WebTraceLocation&, Task*, long long delay
Ms) { }; |
| 76 | 73 |
| 77 // Returns a WebTaskRunner bound to the underlying scheduler's default task
queue. | 74 // Returns a WebTaskRunner bound to the underlying scheduler's default task
queue. |
| 78 virtual WebTaskRunner* taskRunner() { return nullptr; } | 75 virtual WebTaskRunner* taskRunner() { return nullptr; } |
| 79 | 76 |
| 80 virtual bool isCurrentThread() const = 0; | 77 virtual bool isCurrentThread() const = 0; |
| 81 virtual PlatformThreadId threadId() const { return 0; } | 78 virtual PlatformThreadId threadId() const { return 0; } |
| 82 | 79 |
| 83 virtual void addTaskObserver(TaskObserver*) { } | 80 virtual void addTaskObserver(TaskObserver*) { } |
| 84 virtual void removeTaskObserver(TaskObserver*) { } | 81 virtual void removeTaskObserver(TaskObserver*) { } |
| 85 | 82 |
| 86 // Returns the scheduler associated with the thread. | 83 // Returns the scheduler associated with the thread. |
| 87 virtual WebScheduler* scheduler() const = 0; | 84 virtual WebScheduler* scheduler() const = 0; |
| 88 | 85 |
| 89 virtual ~WebThread() { } | 86 virtual ~WebThread() { } |
| 90 | |
| 91 #ifdef INSIDE_BLINK | |
| 92 // Helpers for posting bound functions as tasks. | |
| 93 void postTask(const WebTraceLocation&, PassOwnPtr<Function<void()>>); | |
| 94 void postDelayedTask(const WebTraceLocation&, PassOwnPtr<Function<void()>>,
long long delayMs); | |
| 95 #endif | |
| 96 }; | 87 }; |
| 97 | 88 |
| 98 } // namespace blink | 89 } // namespace blink |
| 99 | 90 |
| 100 #endif | 91 #endif |
| OLD | NEW |