Index: base/message_loop.cc |
diff --git a/base/message_loop.cc b/base/message_loop.cc |
index 546467089289573b1a67fb271de75419f89aa46c..4476dd544c526a47bcad592ddc5bbf153df17d40 100644 |
--- a/base/message_loop.cc |
+++ b/base/message_loop.cc |
@@ -78,8 +78,10 @@ MessageLoop* MessageLoop::current() { |
MessageLoop::MessageLoop(Type type) |
: type_(type), |
+ work_queue_(new TaskQueue), |
nestable_tasks_allowed_(true), |
exception_restoration_(false), |
+ incoming_queue_(new TaskQueue), |
state_(NULL), |
next_sequence_num_(0) { |
DCHECK(!current()) << "should only have one message loop per thread"; |
@@ -270,8 +272,8 @@ void MessageLoop::PostTask_Helper( |
{ |
AutoLock locked(incoming_queue_lock_); |
- bool was_empty = incoming_queue_.empty(); |
- incoming_queue_.push(pending_task); |
+ bool was_empty = incoming_queue_->empty(); |
+ incoming_queue_->push(pending_task); |
if (!was_empty) |
return; // Someone else should have started the sub-pump. |
@@ -346,24 +348,25 @@ void MessageLoop::ReloadWorkQueue() { |
// work_queue_ by waiting until the last minute (work_queue_ is empty) to |
// load. That reduces the number of locks-per-task significantly when our |
// queues get large. |
- if (!work_queue_.empty()) |
+ if (!work_queue_->empty()) |
return; // Wait till we *really* need to lock and load. |
// Acquire all we can from the inter-thread queue with one lock acquisition. |
{ |
AutoLock lock(incoming_queue_lock_); |
- if (incoming_queue_.empty()) |
+ if (incoming_queue_->empty()) |
return; |
- std::swap(incoming_queue_, work_queue_); |
- DCHECK(incoming_queue_.empty()); |
+ // std::queue does not define a swap specialization. Swap the pointers. |
+ incoming_queue_.swap(work_queue_); |
+ DCHECK(incoming_queue_->empty()); |
} |
} |
bool MessageLoop::DeletePendingTasks() { |
- bool did_work = !work_queue_.empty(); |
- while (!work_queue_.empty()) { |
- PendingTask pending_task = work_queue_.front(); |
- work_queue_.pop(); |
+ bool did_work = !work_queue_->empty(); |
+ while (!work_queue_->empty()) { |
+ PendingTask pending_task = work_queue_->front(); |
+ work_queue_->pop(); |
if (!pending_task.delayed_run_time.is_null()) { |
// We want to delete delayed tasks in the same order in which they would |
// normally be deleted in case of any funny dependencies between delayed |
@@ -413,13 +416,13 @@ bool MessageLoop::DoWork() { |
for (;;) { |
ReloadWorkQueue(); |
- if (work_queue_.empty()) |
+ if (work_queue_->empty()) |
break; |
// Execute oldest task. |
do { |
- PendingTask pending_task = work_queue_.front(); |
- work_queue_.pop(); |
+ PendingTask pending_task = work_queue_->front(); |
+ work_queue_->pop(); |
if (!pending_task.delayed_run_time.is_null()) { |
AddToDelayedWorkQueue(pending_task); |
// If we changed the topmost task, then it is time to re-schedule. |
@@ -429,7 +432,7 @@ bool MessageLoop::DoWork() { |
if (DeferOrRunPendingTask(pending_task)) |
return true; |
} |
- } while (!work_queue_.empty()); |
+ } while (!work_queue_->empty()); |
} |
// Nothing happened. |