Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1385)

Side by Side Diff: base/message_loop.h

Issue 14387002: Adding TryPostTask to the message loop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bool Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | base/message_loop.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 438
431 // Adds the pending task to delayed_work_queue_. 439 // Adds the pending task to delayed_work_queue_.
432 void AddToDelayedWorkQueue(const base::PendingTask& pending_task); 440 void AddToDelayedWorkQueue(const base::PendingTask& pending_task);
433 441
434 // Adds the pending task to our incoming_queue_. 442 // Adds the pending task to our incoming_queue_.
435 // 443 //
436 // Caller retains ownership of |pending_task|, but this function will 444 // Caller retains ownership of |pending_task|, but this function will
437 // reset the value of pending_task->task. This is needed to ensure 445 // reset the value of pending_task->task. This is needed to ensure
438 // that the posting call stack does not retain pending_task->task 446 // that the posting call stack does not retain pending_task->task
439 // beyond this function call. 447 // beyond this function call.
440 void AddToIncomingQueue(base::PendingTask* pending_task); 448 // If |use_try_lock| is true, The function fails if another thread is
449 // queuing or dequeing at that moment. In that case the function returns
450 // false. If |use_try_lock| is false there is no need to check the
451 // return value.
452 bool AddToIncomingQueue(base::PendingTask* pending_task, bool use_try_lock);
441 453
442 // Load tasks from the incoming_queue_ into work_queue_ if the latter is 454 // 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 455 // empty. The former requires a lock to access, while the latter is directly
444 // accessible on this thread. 456 // accessible on this thread.
445 void ReloadWorkQueue(); 457 void ReloadWorkQueue();
446 458
447 // Delete tasks that haven't run yet without running them. Used in the 459 // 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 460 // destructor to make sure all the task's destructors get called. Returns
449 // true if some work was done. 461 // true if some work was done.
450 bool DeletePendingTasks(); 462 bool DeletePendingTasks();
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 725
714 } // namespace base 726 } // namespace base
715 727
716 // TODO(brettw) remove this when all users are updated to explicitly use the 728 // TODO(brettw) remove this when all users are updated to explicitly use the
717 // namespace 729 // namespace
718 using base::MessageLoop; 730 using base::MessageLoop;
719 using base::MessageLoopForIO; 731 using base::MessageLoopForIO;
720 using base::MessageLoopForUI; 732 using base::MessageLoopForUI;
721 733
722 #endif // BASE_MESSAGE_LOOP_H_ 734 #endif // BASE_MESSAGE_LOOP_H_
OLDNEW
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | base/message_loop.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698