As the name describes, this class is a taskqueue, which is the task queue, adding tasks to the queue, and then messageloop to execute the task, the more concerned functions are as follows:
BOOL Incomingtaskqueue::addtoincomingqueue ( const tracked_objects::location& from_here, const Closure & Task, timedelta delay, bool nestable) { autolock locked (incoming_queue_lock_); Pendingtask Pending_task ( from_here, task, calculatedelayedruntime (delay), nestable); Return Postpendingtask (&pending_task);}
The closeure encapsulated in the Pendingtask this inside is worth noting is from_here this is actually a location information, record the current code is in the file, the code is in the line, this is mainly for tracking, have to say that Google in this respect is still considered very thoughtful. See below Postpendingtask (&pending_task); this function;
BOOL Incomingtaskqueue::P ostpendingtask (pendingtask* pending_task) {//Warning:don ' t try to short-circuit, and handle T His thread's tasks more//directly, as it could starve handling of foreign threads. Put every task//into the this queue. This should only being called while the lock is taken. Incoming_queue_lock_. Assertacquired (); if (!message_loop_) {pending_task->task. Reset (); return false; }//Initialize the sequence number. The sequence number is used for delayed//tasks (to faciliate FIFO sorting when both tasks have the same//Delayed_run_ Time value) and for identifying the task in about:tracing. Pending_task->sequence_num = next_sequence_num_++; Message_loop_->task_annotator ()->didqueuetask ("Messageloop::P osttask", *pending_task); BOOL Was_empty = Incoming_queue_.empty (); Incoming_queue_.push (*pending_task); Pending_task->task. Reset (); Wake up the pump. Message_loop_->schedulework (WAS_empty); return true;}
Obviously, put the task in the queue and then call Message_loop_->schedulework (Was_empty); That is, execute the scheduled task, the code is as follows
void Messageloop::schedulework (bool was_empty) { if (Was_empty | | Alwaysnotifypump (type_)) pump_->schedulework ();}
and turned it over to pump.
void Messagepumpdefault::schedulework () { ///Since This can is called on any thread, we need to ensure so our RUN
//Loop wakes up. Event_. Signal ();}
This is also simple, is the event to believe, why to do so, this depends on the code to see pump know, because in the absence of the task will always be on the event above waiting for the waiter, when the confidence began to cycle Value Line task.
Google Base's Incomingtaskqueue