OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_MESSAGE_LOOP_H_ | 5 #ifndef BASE_MESSAGE_LOOP_H_ |
6 #define BASE_MESSAGE_LOOP_H_ | 6 #define BASE_MESSAGE_LOOP_H_ |
7 | 7 |
8 #include <queue> | 8 #include <queue> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 #elif defined(USE_MESSAGEPUMP_LINUX) && !defined(OS_NACL) | 37 #elif defined(USE_MESSAGEPUMP_LINUX) && !defined(OS_NACL) |
38 #include "base/message_pump_linux.h" | 38 #include "base/message_pump_linux.h" |
39 #else | 39 #else |
40 #include "base/message_pump_gtk.h" | 40 #include "base/message_pump_gtk.h" |
41 #endif | 41 #endif |
42 | 42 |
43 #endif | 43 #endif |
44 #endif | 44 #endif |
45 | 45 |
46 namespace base { | 46 namespace base { |
47 | |
48 class HistogramBase; | 47 class HistogramBase; |
48 class MessageLoopLockTest; | |
49 class RunLoop; | 49 class RunLoop; |
50 class ThreadTaskRunnerHandle; | 50 class ThreadTaskRunnerHandle; |
51 #if defined(OS_ANDROID) | 51 #if defined(OS_ANDROID) |
52 class MessagePumpForUI; | 52 class MessagePumpForUI; |
53 #endif | 53 #endif |
54 | 54 |
55 // A MessageLoop is used to process events for a particular thread. There is | 55 // A MessageLoop is used to process events for a particular thread. There is |
56 // at most one MessageLoop instance per thread. | 56 // at most one MessageLoop instance per thread. |
57 // | 57 // |
58 // Events include at a minimum Task instances submitted to PostTask and its | 58 // Events include at a minimum Task instances submitted to PostTask and its |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 // The NonNestable variants work similarly except that they promise never to | 161 // The NonNestable variants work similarly except that they promise never to |
162 // dispatch the task from a nested invocation of MessageLoop::Run. Instead, | 162 // dispatch the task from a nested invocation of MessageLoop::Run. Instead, |
163 // such tasks get deferred until the top-most MessageLoop::Run is executing. | 163 // such tasks get deferred until the top-most MessageLoop::Run is executing. |
164 // | 164 // |
165 // The MessageLoop takes ownership of the Task, and deletes it after it has | 165 // The MessageLoop takes ownership of the Task, and deletes it after it has |
166 // been Run(). | 166 // been Run(). |
167 // | 167 // |
168 // PostTask(from_here, task) is equivalent to | 168 // PostTask(from_here, task) is equivalent to |
169 // PostDelayedTask(from_here, task, 0). | 169 // PostDelayedTask(from_here, task, 0). |
170 // | 170 // |
171 // The TryPostTask is meant for the cases where the calling thread cannot | |
172 // block. If posting the task will block, the call returns false, the task | |
173 // is not posted but the task is consumed anyways. | |
174 // | |
171 // NOTE: These methods may be called on any thread. The Task will be invoked | 175 // NOTE: These methods may be called on any thread. The Task will be invoked |
172 // on the thread that executes MessageLoop::Run(). | 176 // on the thread that executes MessageLoop::Run(). |
173 void PostTask( | 177 void PostTask( |
174 const tracked_objects::Location& from_here, | 178 const tracked_objects::Location& from_here, |
175 const base::Closure& task); | 179 const base::Closure& task); |
176 | 180 |
181 bool TryPostTask( | |
182 const tracked_objects::Location& from_here, | |
183 const base::Closure& task); | |
184 | |
177 void PostDelayedTask( | 185 void PostDelayedTask( |
178 const tracked_objects::Location& from_here, | 186 const tracked_objects::Location& from_here, |
179 const base::Closure& task, | 187 const base::Closure& task, |
180 base::TimeDelta delay); | 188 base::TimeDelta delay); |
181 | 189 |
182 void PostNonNestableTask( | 190 void PostNonNestableTask( |
183 const tracked_objects::Location& from_here, | 191 const tracked_objects::Location& from_here, |
184 const base::Closure& task); | 192 const base::Closure& task); |
185 | 193 |
186 void PostNonNestableDelayedTask( | 194 void PostNonNestableDelayedTask( |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 #elif defined(OS_POSIX) && !defined(OS_IOS) | 403 #elif defined(OS_POSIX) && !defined(OS_IOS) |
396 base::MessagePumpLibevent* pump_libevent() { | 404 base::MessagePumpLibevent* pump_libevent() { |
397 return static_cast<base::MessagePumpLibevent*>(pump_.get()); | 405 return static_cast<base::MessagePumpLibevent*>(pump_.get()); |
398 } | 406 } |
399 #endif | 407 #endif |
400 | 408 |
401 scoped_refptr<base::MessagePump> pump_; | 409 scoped_refptr<base::MessagePump> pump_; |
402 | 410 |
403 private: | 411 private: |
404 friend class base::RunLoop; | 412 friend class base::RunLoop; |
413 friend class base::MessageLoopLockTest; | |
405 | 414 |
406 // A function to encapsulate all the exception handling capability in the | 415 // A function to encapsulate all the exception handling capability in the |
407 // stacks around the running of a main message loop. It will run the message | 416 // stacks around the running of a main message loop. It will run the message |
408 // loop in a SEH try block or not depending on the set_SEH_restoration() | 417 // loop in a SEH try block or not depending on the set_SEH_restoration() |
409 // flag invoking respectively RunInternalInSEHFrame() or RunInternal(). | 418 // flag invoking respectively RunInternalInSEHFrame() or RunInternal(). |
410 void RunHandler(); | 419 void RunHandler(); |
411 | 420 |
412 #if defined(OS_WIN) | 421 #if defined(OS_WIN) |
413 __declspec(noinline) void RunInternalInSEHFrame(); | 422 __declspec(noinline) void RunInternalInSEHFrame(); |
414 #endif | 423 #endif |
(...skipping 15 matching lines...) Expand all Loading... | |
430 | 439 |
431 // Adds the pending task to delayed_work_queue_. | 440 // Adds the pending task to delayed_work_queue_. |
432 void AddToDelayedWorkQueue(const base::PendingTask& pending_task); | 441 void AddToDelayedWorkQueue(const base::PendingTask& pending_task); |
433 | 442 |
434 // Adds the pending task to our incoming_queue_. | 443 // Adds the pending task to our incoming_queue_. |
435 // | 444 // |
436 // Caller retains ownership of |pending_task|, but this function will | 445 // Caller retains ownership of |pending_task|, but this function will |
437 // reset the value of pending_task->task. This is needed to ensure | 446 // reset the value of pending_task->task. This is needed to ensure |
438 // that the posting call stack does not retain pending_task->task | 447 // that the posting call stack does not retain pending_task->task |
439 // beyond this function call. | 448 // beyond this function call. |
440 void AddToIncomingQueue(base::PendingTask* pending_task); | 449 // If |use_try_lock| is true, The function fails if another thread is |
450 // queuing or dequeing at that moment. In that case the function returns | |
451 // false. If |use_try_lock| is false there is no need to check the | |
452 // return value. | |
jar (doing other things)
2013/04/29 17:27:18
Reading the whole comment, starting on line 443, p
cpu_(ooo_6.6-7.5)
2013/04/30 05:26:04
Done.
| |
453 bool AddToIncomingQueue(base::PendingTask* pending_task, bool use_try_lock); | |
441 | 454 |
442 // Load tasks from the incoming_queue_ into work_queue_ if the latter is | 455 // Load tasks from the incoming_queue_ into work_queue_ if the latter is |
443 // empty. The former requires a lock to access, while the latter is directly | 456 // empty. The former requires a lock to access, while the latter is directly |
444 // accessible on this thread. | 457 // accessible on this thread. |
445 void ReloadWorkQueue(); | 458 void ReloadWorkQueue(); |
446 | 459 |
447 // Delete tasks that haven't run yet without running them. Used in the | 460 // Delete tasks that haven't run yet without running them. Used in the |
448 // destructor to make sure all the task's destructors get called. Returns | 461 // destructor to make sure all the task's destructors get called. Returns |
449 // true if some work was done. | 462 // true if some work was done. |
450 bool DeletePendingTasks(); | 463 bool DeletePendingTasks(); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 | 726 |
714 } // namespace base | 727 } // namespace base |
715 | 728 |
716 // TODO(brettw) remove this when all users are updated to explicitly use the | 729 // TODO(brettw) remove this when all users are updated to explicitly use the |
717 // namespace | 730 // namespace |
718 using base::MessageLoop; | 731 using base::MessageLoop; |
719 using base::MessageLoopForIO; | 732 using base::MessageLoopForIO; |
720 using base::MessageLoopForUI; | 733 using base::MessageLoopForUI; |
721 | 734 |
722 #endif // BASE_MESSAGE_LOOP_H_ | 735 #endif // BASE_MESSAGE_LOOP_H_ |
OLD | NEW |