如同名称描述的那样,这个类就是个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上面等侍,当置信了以后又开始循环值行任务。 

google base之IncomingTaskQueue的更多相关文章

  1. colmap编译过程中出现,无法解析的外部符号错误 “__cdecl google::base::CheckOpMessageBuilder::ForVar1(void)”

    错误提示: >colmap.lib(matching.obj) : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: cl ...

  2. google base库之simplethread

    // This is the base SimpleThread. You can derive from it and implement the // virtual Run method, or ...

  3. google base 之MessagePumpForUI

    base库中比较有意思就是这个类了,如同很多界面库一样,创建了一个隐藏窗口来处理需要在界面线程处理的消息,大体原理也就是需要执行task的时候发送一个自定义的消息,当窗口接收到task的时候调用保存起 ...

  4. google base库中的WaitableEvent

    这个类说白了就是对windows event的封装,没有什么特别的,常规做法,等侍另一线程无非就是等侍事件置信waitsingleobject,通知事件无非就是setevent,一看就明白,不就详解, ...

  5. google base之LockImpl

    为了兼容不同的平台,这个类采用了impl模式,win平台通过CRITICAL_SECTION, 这样的话还是相对比较简单,具体就不详解了,不过不得不说boost的实现方式就要复杂到哪里去了,当然,好处 ...

  6. 谷歌 google

    google Google是搜索引擎名,也是一家美国上市公司名称.Google公司于1998年9月7日以私有股份公司的形式创立,以设计并管理一个互联网的搜索引擎.Google公司的总部称作“Googl ...

  7. Windows平台下和跨平台的相关公共库

    以下主要包含windows下公共库以及跨平台公共库: 1. google base库:google下chromium项目的跨平台公共库: 2. vc_common_src:即HP_SOCKET项目中的 ...

  8. Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04 配置参考文献 以及 常见编译问题总结

    Caffe+CUDA7.5+CuDNNv3+OpenCV3.0+Ubuntu14.04  配置参考文献 ---- Wang Xiao Warning: Please make sure the cud ...

  9. web2.0最全的国外API应用集合

    web2.0最全的国外API应用集合 原文地址:http://www.buguat.com/post/98.html 2.0时代,越来越多的API被大家广泛应用,如果你还不了解API是何物,请看这里的 ...

随机推荐

  1. ParNew收集器

    ParNew收集器其实就是Serial收集器的多线程版本,除了使用多条线程进行垃圾收集之外,其余行为包括Serial收集器可用的所有控制参数,其中Par是Paralle简写l 并行(Parallel) ...

  2. PHP定义数组常量

    最先想到的方法是这样: define('SIGN_CODE', array('9df512','59gf1g','5eg7h1','g1agf5','f5e151','g51gfr','a5481s' ...

  3. Http的Post和Get

    原文:http://www.cnblogs.com/hyddd/archive/2009/03/31/1426026.html Http定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET, ...

  4. HDU 3030 - Increasing Speed Limits

    Problem Description You were driving along a highway when you got caught by the road police for spee ...

  5. Linux下Matlab崩溃的解决方法

    猜想主要是因为图形显示用了OpenGL加速造成不稳定. 我的运行环境是: Ubuntu 10.04 LTS 64bit Matlab R2010b 解决方法是启动时用: $MATLAB_DIR/bin ...

  6. js:关于IE6/7下new Date(值)输出为NaN的解决方案

    不得不再次说,万恶的IE,你太守旧了吧,这里出错的原因是IE的时间格式,不是2012-01-23(很多人喜欢用这样的格式) 而是2012/01/23(怎么感觉像是在用VB6和access啊) 搞了好久 ...

  7. Hive的安装配置

    Hive的安装配置 Hive的安装配置 安装前准备 下载Hive版本1.2.1: 1.[root@iZ28gvqe4biZ ~]# wget http://mirror.bit.edu.cn/apac ...

  8. 6 支持向量机SVM

    注:理论部分参考:http://blog.csdn.net/v_july_v/article/details/7624837 (1)SVM是现成最好的分类器,这里“现成”指的是分类器不加修改即可直接使 ...

  9. linux下实现自己的shell解释器

    实现一个自己的shell解释器,其原理比较简单,首先获取用户的输入,通过fork()函数获取两个进程(父子进程),子进程通过execvp()函数继续进行,此时父进程一直在等待子进程的结束,待都结束了就 ...

  10. [Backbone.js]如何用backbone写一个仿网页版微信的webapp?

    var Chat = Backbone.Model.extend({ idAttribute:'id', initialize:function(options){ var users = this. ...