| 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 MOJO_PUBLIC_CPP_UTILITY_RUN_LOOP_H_ | 5 #ifndef MOJO_PUBLIC_CPP_UTILITY_RUN_LOOP_H_ |
| 6 #define MOJO_PUBLIC_CPP_UTILITY_RUN_LOOP_H_ | 6 #define MOJO_PUBLIC_CPP_UTILITY_RUN_LOOP_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <queue> | 9 #include <queue> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 // Registers a RunLoopHandler for the specified handle. Only one handler can | 34 // Registers a RunLoopHandler for the specified handle. Only one handler can |
| 35 // be registered for a specified handle. | 35 // be registered for a specified handle. |
| 36 void AddHandler(RunLoopHandler* handler, | 36 void AddHandler(RunLoopHandler* handler, |
| 37 const Handle& handle, | 37 const Handle& handle, |
| 38 MojoHandleSignals handle_signals, | 38 MojoHandleSignals handle_signals, |
| 39 MojoDeadline deadline); | 39 MojoDeadline deadline); |
| 40 void RemoveHandler(const Handle& handle); | 40 void RemoveHandler(const Handle& handle); |
| 41 bool HasHandler(const Handle& handle) const; | 41 bool HasHandler(const Handle& handle) const; |
| 42 | 42 |
| 43 // Runs the loop servicing handles as they are ready. This returns when Quit() | 43 // Runs the loop servicing handles and tasks as they are ready. This returns |
| 44 // is invoked, or there no more handles. | 44 // when Quit() is invoked, or there are no more handles nor tasks. |
| 45 void Run(); | 45 void Run(); |
| 46 | 46 |
| 47 // Runs the loop servicing any handles that are ready. Does not wait for | 47 // Runs the loop servicing any handles and tasks that are ready. Does not wait |
| 48 // handles to become ready before returning. Returns early if Quit() is | 48 // for handles or tasks to become ready before returning. Returns early if |
| 49 // invoked. | 49 // Quit() is invoked. |
| 50 void RunUntilIdle(); | 50 void RunUntilIdle(); |
| 51 | 51 |
| 52 void Quit(); | 52 void Quit(); |
| 53 | 53 |
| 54 // Adds a task to be performed after delay has elapsed. Must be posted to the | 54 // Adds a task to be performed after delay has elapsed. Must be posted to the |
| 55 // current thread's RunLoop. | 55 // current thread's RunLoop. |
| 56 void PostDelayedTask(const Closure& task, MojoTimeTicks delay); | 56 void PostDelayedTask(const Closure& task, MojoTimeTicks delay); |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 struct RunState; | 59 struct RunState; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 76 | 76 |
| 77 typedef std::map<Handle, HandlerData> HandleToHandlerData; | 77 typedef std::map<Handle, HandlerData> HandleToHandlerData; |
| 78 | 78 |
| 79 // Used for NotifyHandlers to specify whether HandlerData's |deadline| | 79 // Used for NotifyHandlers to specify whether HandlerData's |deadline| |
| 80 // should be checked prior to notifying. | 80 // should be checked prior to notifying. |
| 81 enum CheckDeadline { | 81 enum CheckDeadline { |
| 82 CHECK_DEADLINE, | 82 CHECK_DEADLINE, |
| 83 IGNORE_DEADLINE | 83 IGNORE_DEADLINE |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 // Do one unit of delayed work, if eligible. | 86 // Runs the loop servicing any handles and tasks that are ready. If |
| 87 void DoDelayedWork(); | 87 // |until_idle| is true, does not wait for handles or tasks to become ready |
| 88 // before returning. Returns early if Quit() is invoked. |
| 89 void RunInternal(bool until_idle); |
| 88 | 90 |
| 89 // Waits for a handle to be ready. Returns after servicing at least one | 91 // Do one unit of delayed work, if eligible. Returns true is a task was run. |
| 90 // handle (or there are no more handles) unless |non_blocking| is true, | 92 bool DoDelayedWork(); |
| 91 // in which case it will also return if servicing at least one handle | 93 |
| 92 // would require blocking. Returns true if a RunLoopHandler was notified. | 94 // Waits for a handle to be ready or until the next task must be run. Returns |
| 95 // after servicing at least one handle (or there are no more handles) unless |
| 96 // a task must be run or |non_blocking| is true, in which case it will also |
| 97 // return if no task is registered and servicing at least one handle would |
| 98 // require blocking. Returns true if a RunLoopHandler was notified. |
| 93 bool Wait(bool non_blocking); | 99 bool Wait(bool non_blocking); |
| 94 | 100 |
| 95 // Notifies handlers of |error|. If |check| == CHECK_DEADLINE, this will | 101 // Notifies handlers of |error|. If |check| == CHECK_DEADLINE, this will |
| 96 // only notify handlers whose deadline has expired and skips the rest. | 102 // only notify handlers whose deadline has expired and skips the rest. |
| 97 // Returns true if a RunLoopHandler was notified. | 103 // Returns true if a RunLoopHandler was notified. |
| 98 bool NotifyHandlers(MojoResult error, CheckDeadline check); | 104 bool NotifyHandlers(MojoResult error, CheckDeadline check); |
| 99 | 105 |
| 100 // Removes the first invalid handle. This is called if MojoWaitMany() finds an | 106 // Removes the first invalid handle. This is called if MojoWaitMany() finds an |
| 101 // invalid handle. Returns true if a RunLoopHandler was notified. | 107 // invalid handle. Returns true if a RunLoopHandler was notified. |
| 102 bool RemoveFirstInvalidHandle(const WaitState& wait_state); | 108 bool RemoveFirstInvalidHandle(const WaitState& wait_state); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 uint64_t next_sequence_number_; | 140 uint64_t next_sequence_number_; |
| 135 typedef std::priority_queue<PendingTask> DelayedTaskQueue; | 141 typedef std::priority_queue<PendingTask> DelayedTaskQueue; |
| 136 DelayedTaskQueue delayed_tasks_; | 142 DelayedTaskQueue delayed_tasks_; |
| 137 | 143 |
| 138 MOJO_DISALLOW_COPY_AND_ASSIGN(RunLoop); | 144 MOJO_DISALLOW_COPY_AND_ASSIGN(RunLoop); |
| 139 }; | 145 }; |
| 140 | 146 |
| 141 } // namespace mojo | 147 } // namespace mojo |
| 142 | 148 |
| 143 #endif // MOJO_PUBLIC_CPP_UTILITY_RUN_LOOP_H_ | 149 #endif // MOJO_PUBLIC_CPP_UTILITY_RUN_LOOP_H_ |
| OLD | NEW |