google base之IncomingTaskQueue
2024-09-21 12:52:37
如同名称描述的那样,这个类就是个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上面等侍,当置信了以后又开始循环值行任务。
最新文章
- 如何更高效地定制你的bootstrap
- 使用 Intel HAXM 为 Android 模拟器加速,媲美真机
- oracle触发器设置uuid变量
- 云极知客开放平台接口调用方法(C#)
- 帝吧出征FB:这李毅吧的“爆吧”文化是如何形成的
- submit回车提交影响
- nginx反向代理原理和配置讲解
- 客户调用COM流程
- Codeforces 296C Greg and Array
- php 之 文件操作(0524)
- javascript get获取参数
- Linux系统(三)系统基础扫盲大全
- MPLS VPN随堂笔记3
- javascript Json和String互转
- 论文阅读笔记四十四:RetinaNet:Focal Loss for Dense Object Detection(ICCV2017)
- Pfsense2.34中文版
- Paper/ Overview | CNN(未完待续)
- uni-app,wex5,APPcan,ApiCloud几款国内webapp开发框架的选型对比
- uva 10918 - Tri Tiling(规律)
- [转]Struts2多个文件上传