| 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 |
| 11 #include "mojo/public/c/system/time.h" | 11 #include "mojo/public/c/system/time.h" |
| 12 #include "mojo/public/cpp/bindings/callback.h" | 12 #include "mojo/public/cpp/bindings/callback.h" |
| 13 #include "mojo/public/cpp/system/handle.h" | 13 #include "mojo/public/cpp/system/handle.h" |
| 14 #include "mojo/public/cpp/system/macros.h" | 14 #include "mojo/public/cpp/system/macros.h" |
| 15 #include "mojo/public/cpp/system/message_pipe.h" | 15 #include "mojo/public/cpp/system/message_pipe.h" |
| 16 | 16 |
| 17 namespace mojo { | 17 namespace mojo { |
| 18 | 18 |
| 19 class RunLoopHandler; | 19 class RunLoopHandler; |
| 20 | 20 |
| 21 // Watches handles for signals and calls event handlers when they occur. Also | 21 // Watches handles for signals and calls event handlers when they occur. Also |
| 22 // executes delayed tasks. This class should only be used by a single thread. | 22 // executes delayed tasks. This class should only be used by a single thread. |
| 23 class RunLoop { | 23 class RunLoop { |
| 24 public: | 24 public: |
| 25 RunLoop(); | 25 RunLoop(); |
| 26 ~RunLoop(); | 26 ~RunLoop(); |
| 27 | 27 |
| 28 // Sets up state needed for RunLoop. This must be invoked before creating a | |
| 29 // RunLoop. | |
| 30 static void SetUp(); | |
| 31 | |
| 32 // Cleans state created by Setup(). | |
| 33 static void TearDown(); | |
| 34 | |
| 35 // Returns the RunLoop for the current thread. Returns null if not yet | 28 // Returns the RunLoop for the current thread. Returns null if not yet |
| 36 // created. | 29 // created. |
| 37 static RunLoop* current(); | 30 static RunLoop* current(); |
| 38 | 31 |
| 39 // Registers a RunLoopHandler for the specified handle. It is an error to | 32 // Registers a RunLoopHandler for the specified handle. It is an error to |
| 40 // register more than one handler for a handle, and crashes the process. | 33 // register more than one handler for a handle, and crashes the process. |
| 41 // | 34 // |
| 42 // The handler's OnHandleReady() method is invoked after one of the signals in | 35 // The handler's OnHandleReady() method is invoked after one of the signals in |
| 43 // |handle_signals| occurs. Note that the handler remains registered until | 36 // |handle_signals| occurs. Note that the handler remains registered until |
| 44 // explicitly removed or an error occurs. | 37 // explicitly removed or an error occurs. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 uint64_t next_sequence_number_; | 142 uint64_t next_sequence_number_; |
| 150 typedef std::priority_queue<PendingTask> DelayedTaskQueue; | 143 typedef std::priority_queue<PendingTask> DelayedTaskQueue; |
| 151 DelayedTaskQueue delayed_tasks_; | 144 DelayedTaskQueue delayed_tasks_; |
| 152 | 145 |
| 153 MOJO_DISALLOW_COPY_AND_ASSIGN(RunLoop); | 146 MOJO_DISALLOW_COPY_AND_ASSIGN(RunLoop); |
| 154 }; | 147 }; |
| 155 | 148 |
| 156 } // namespace mojo | 149 } // namespace mojo |
| 157 | 150 |
| 158 #endif // MOJO_PUBLIC_CPP_UTILITY_RUN_LOOP_H_ | 151 #endif // MOJO_PUBLIC_CPP_UTILITY_RUN_LOOP_H_ |
| OLD | NEW |