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

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: changes per jar comments 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..ef969f399834ff09bf6d5014fa384d5235c00470 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
@@ -437,7 +446,11 @@ class BASE_EXPORT MessageLoop : public base::MessagePump::Delegate {
// 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);
+ // If |use_try_lock| is true, The function fails if another thread is
+ // queuing or dequeing at that moment. In that case the function returns
+ // false. If |use_try_lock| is false there is no need to check the
+ // 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.
+ 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