如同名称描述的那样,这个类就是个taskqueue,也就是任务队列,添加任务到队列,然后由MessageLoop去执行task,比较关心的函数如下:

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);
}

将closeure封装到了 PendingTask 这个里边值得注意的是 from_here 这个其实就是个位置信息,记录了当前代码所在文件,代码所在的行,这个主要是为了追踪,不得不说google在这方面还是考虑得非常周全的。下面看PostPendingTask(&pending_task);这个函数;

bool IncomingTaskQueue::PostPendingTask(PendingTask* pending_task) {
// Warning: Don't try to short-circuit, and handle this thread's tasks more
// directly, as it could starve handling of foreign threads. Put every task
// into this queue. // This should only be 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 two 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::PostTask",
*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;
}

很显然,将task放到队列,然后调用 message_loop_->ScheduleWork(was_empty);  也就是执行计划任务,代码如下

void MessageLoop::ScheduleWork(bool was_empty) {
if (was_empty || AlwaysNotifyPump(type_))
pump_->ScheduleWork();
}

又转交给了pump

void MessagePumpDefault::ScheduleWork() {
// Since this can be called on any thread, we need to ensure that our Run
// loop wakes up.
event_.Signal();
}

这个也简单,就是对事件置信,为什么要这么做呢,这个要看pump的代码才知道,因为在没有任务的时候会一直在event上面等侍,当置信了以后又开始循环值行任务。 

最新文章

  1. 如何更高效地定制你的bootstrap
  2. 使用 Intel HAXM 为 Android 模拟器加速,媲美真机
  3. oracle触发器设置uuid变量
  4. 云极知客开放平台接口调用方法(C#)
  5. 帝吧出征FB:这李毅吧的“爆吧”文化是如何形成的
  6. submit回车提交影响
  7. nginx反向代理原理和配置讲解
  8. 客户调用COM流程
  9. Codeforces 296C Greg and Array
  10. php 之 文件操作(0524)
  11. javascript get获取参数
  12. Linux系统(三)系统基础扫盲大全
  13. MPLS VPN随堂笔记3
  14. javascript Json和String互转
  15. 论文阅读笔记四十四:RetinaNet:Focal Loss for Dense Object Detection(ICCV2017)
  16. Pfsense2.34中文版
  17. Paper/ Overview | CNN(未完待续)
  18. uni-app,wex5,APPcan,ApiCloud几款国内webapp开发框架的选型对比
  19. uva 10918 - Tri Tiling(规律)
  20. [转]Struts2多个文件上传

热门文章

  1. 怎样在xcode中使用storyboard
  2. oracle子查询
  3. mma ctf 1st && csaw 2015
  4. asp.net几种<% %>用法
  5. WindowsForm 公共控件 菜单和工具栏
  6. 井字棋(Tic-Tac-Toe)
  7. javascript二级联动
  8. React 从0开始 消息传递
  9. Delphi资源文件(全面分析之位图、光标、图标、AVI、JPEG、Wave)
  10. sqlserver 增加用户并分配权限