| 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
|
|
|