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

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: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/message_loop.cc » ('j') | base/message_loop.cc » ('J')
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..070fd2cc4d91c2c4c93e87575cea0886636464b8 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -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,
@@ -437,7 +445,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.
+ 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') | base/message_loop.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698