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

Unified 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: change comment 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/message_loop.h
diff --git a/base/message_loop.h b/base/message_loop.h
index dbe75a57f9f410ae1a672745c1daffdb8ee4ce37..eb0885ed5b0bbf0413ed3fa370510db4ce828060 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -44,8 +44,8 @@
#endif
namespace base {
-
class HistogramBase;
+class MessageLoopLockTest;
class RunLoop;
class ThreadTaskRunnerHandle;
#if defined(OS_ANDROID)
@@ -168,12 +168,20 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
// PostTask(from_here, task) is equivalent to
// PostDelayedTask(from_here, task, 0).
//
+ // The TryPostTask is meant for the cases where the calling thread cannot
+ // block. If posting the task will block, the call returns false, the task
+ // is not posted but the task is consumed anyways.
+ //
// NOTE: These methods may be called on any thread. The Task will be invoked
// on the thread that executes MessageLoop::Run().
void PostTask(
const tracked_objects::Location& from_here,
const base::Closure& task);
+ bool TryPostTask(
+ const tracked_objects::Location& from_here,
+ const base::Closure& task);
+
void PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
@@ -402,6 +410,7 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
private:
friend class base::RunLoop;
+ friend class base::MessageLoopLockTest;
// A function to encapsulate all the exception handling capability in the
// stacks around the running of a main message loop. It will run the message
@@ -431,13 +440,21 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
// Adds the pending task to delayed_work_queue_.
void AddToDelayedWorkQueue(const base::PendingTask& pending_task);
- // Adds the pending task to our incoming_queue_.
- //
- // Caller retains ownership of |pending_task|, but this function will
- // reset the value of pending_task->task. This is needed to ensure
- // that the posting call stack does not retain pending_task->task
+ // This function attempts to add pending task to our incoming_queue_.
+ // The append can only possibly fail when |use_try_lock| is true.
+ //
+ // When |use_try_lock| is true, then this call will avoid blocking if
+ // the related lock is already held, and will in that case (when the
+ // lock is contended) fail to perform the append, and will return false.
+ //
+ // If the call succeeds to append to the queue, then this call
+ // will return true.
+ //
+ // In all cases, the caller retains ownership of |pending_task|, but this
+ // function will reset the value of pending_task->task. This is needed to
+ // ensure that the posting call stack does not retain pending_task->task
// beyond this function call.
- void AddToIncomingQueue(base::PendingTask* pending_task);
+ bool AddToIncomingQueue(base::PendingTask* pending_task, bool use_try_lock);
// Load tasks from the incoming_queue_ into work_queue_ if the latter is
// empty. The former requires a lock to access, while the latter is directly
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698