libubox-runqueue
参考:libubox [4] - uloop runqueue ustream
任务队列是通过uloop定时器实现,把定时器超时时间设置为1,通过uloop事件循环来处理定时器就会处理任务队列中的task。进程任务在任务队列基本上实现,加入子进程退出监控。
procd采用此机制。
1. 数据结构
struct runqueue {
struct safe_list tasks_active; /** 活动任务队列 */
struct safe_list tasks_inactive; /** 不活动任务队列 */
struct uloop_timeout timeout; int running_tasks; /** 当前活动任务数目 */
int max_running_tasks; /** 允许最大活动任务数目 */
bool stopped; /** 是否停止任务队列 */
bool empty; /** 任务队列(包括活动和不活动)是否为空 */ /* called when the runqueue is emptied */
void (*empty_cb)(struct runqueue *q);
}; struct runqueue_task_type {
const char *name; /*
* called when a task is requested to run
*
* The task is removed from the list before this callback is run. It
* can re-arm itself using runqueue_task_add.
*/
void (*run)(struct runqueue *q, struct runqueue_task *t); /*
* called to request cancelling a task
*
* int type is used as an optional hint for the method to be used when
* cancelling the task, e.g. a signal number for processes. Calls
* runqueue_task_complete when done.
*/
void (*cancel)(struct runqueue *q, struct runqueue_task *t, int type); /*
* called to kill a task. must not make any calls to runqueue_task_complete,
* it has already been removed from the list.
*/
void (*kill)(struct runqueue *q, struct runqueue_task *t);
}; struct runqueue_task {
struct safe_list list;
const struct runqueue_task_type *type;
struct runqueue *q; void (*complete)(struct runqueue *q, struct runqueue_task *t); struct uloop_timeout timeout;
int run_timeout; /** >0表示规定此任务执行只有run_timeout毫秒 */
int cancel_timeout; /** >0表示规则任务延取消操作执行只有run_timeout毫秒*/
int cancel_type; bool queued; /** 此任务是否已加入任务队列中 */
bool running; /** 此任务是否活动,即已在活动队列中 */
bool cancelled; /** 此任务是否已被取消 */
}; struct runqueue_process {
struct runqueue_task task;
struct uloop_process proc;
};
2. 函数
任务队列
/**
* 初始化任务队列
*/
void runqueue_init(struct runqueue *q) /**
* 取消所有任务队列
*/
void runqueue_cancel(struct runqueue *q); /**
* 取消活动中的任务
*/
void runqueue_cancel_active(struct runqueue *q); /**
* 取消不活动的任务
*/
void runqueue_cancel_pending(struct runqueue *q); /**
* 杀死所有任务
*/
void runqueue_kill(struct runqueue *q); /**
* 停止所有任务
*/
void runqueue_stop(struct runqueue *q); /**
* 重新开始任务
*/
void runqueue_resume(struct runqueue *q);
任务操作
/**
* 添加新任务到队列尾
*
* @running true-加入活动队列;false-加入不活动队列
*/
void runqueue_task_add(struct runqueue *q, struct runqueue_task *t, bool running); /**
* 添加新任务到队列头
*
* @running true-加入活动队列;false-加入不活动队列
*/
void runqueue_task_add_first(struct runqueue *q, struct runqueue_task *t,
bool running); /**
* 完全任务
*/
void runqueue_task_complete(struct runqueue_task *t); /**
* 取消任务
*/
void runqueue_task_cancel(struct runqueue_task *t, int type); /**
* 杀死任务
*/
void runqueue_task_kill(struct runqueue_task *t);
进程任务
void runqueue_process_add(struct runqueue *q, struct runqueue_process *p,
pid_t pid); /**
* to be used only from runqueue_process callbacks
*/
void runqueue_process_cancel_cb(struct runqueue *q, struct runqueue_task *t,
int type);
void runqueue_process_kill_cb(struct runqueue *q, struct runqueue_task *t);
libubox-runqueue的更多相关文章
- libubox
lbubox是openwrt的一个核心库,封装了一系列基础实用功能,主要提供事件循环,二进制格式处理,linux链表实现和一些JSON辅助处理. 它的目的是以动态链接库方式来提供可重用的通用功能,给其 ...
- openWrt libubox组件之uloop原理分析
1. libubox概述 libubox是openwrt新版本中的一个基础库,有很多应用是基于libubox开发的,如uhttpd,netifd,ubusd等. libubox主要提供以下两种功 ...
- libubox组件(3)——uloop
一:uloop概述 uloop有三个功能: 文件描述符触发事件的监控, timeout定时器处理, 当前进程的子进程的维护 二: uloop的整体框架 1: /** 2: * 初始化事件循环 3: ...
- libubox组件(1)——usock
一:相关API介绍 1.相关源码文件:usocket.h usocket.c 2.类型标志 1: #define USOCK_TCP 0 2: #define USOCK_UDP 1 3: #defi ...
- libubox组件(2)——blob/blobmsg (转载 https://segmentfault.com/a/1190000002391970)
一:blob相关接口 1.数据结构 1: struct blob_attr { 2: uint32_t id_len; /** 高1位为extend标志,高7位存储id, 3: * 低24位存储dat ...
- tr069开源协议EasyCwmp移植
1.平台MT7628 2.交叉编译器及版本信息mipsel-linux + buildroot-gcc463_32bits.tar.bz2 3.创建工作目录lancer@ubuntu:~$ mkdir ...
- openwrt procd启动流程和脚本分析
Linux内核执行start_kernel函数时会调用kernel_init来启动init进程,流程如下图: graph LR A[start_kernel] -->B(rest_init) B ...
- libubox-ustream
参考:libubox [4] - uloop runqueue ustream libubox提供了流缓冲管理,定义在文件ustream.h,ustream.c和ustream-fd.c. 1. 数据 ...
- openwrt procd 运行的一些log
void procd_inittab(void) { #define LINE_LEN 128 FILE *fp = fopen(tab, "r"); struct init_ac ...
随机推荐
- 流畅的python第二章序列构成的数组学习记录
python内置序列类型概览 列表推导和生成器表达式 列表推导是构建列表的快捷方式,而生成器表达式可以用来创建其他任何类型的序列 列表推导的示例 >>>test = [i*2 for ...
- PAAS云服务平台
云计算是一种可以方便.按需从网络訪问的.可配置的.共享的资源池(如网络.server.存储.应用程序和服务)模型,且仅仅需最少的管理(服务提供方交互)就可以高速供应和公布该模型. 云计算平台的核心部分 ...
- liunx系统安装tomcat的方法
安装tomcat前需要先安装jdk,安装jdk的方法参考我的上一篇文章:liunx系统安装jdk的方法 1.下载tomcat 下载地址:http://tomcat.apache.org/downloa ...
- Linux下好用的命令
split -l 10000 articles.json 将文件按行分成多个文件
- Unity 背包道具搜索(2)
上一篇: http://www.cnblogs.com/plateFace/p/6490577.html 上次编写代码只是把逻辑编写出来, 对于里面的代码还存在一下问题 1. 搜索功能没有解耦 2. ...
- oracle update left join查询
对于有的更新语句,要更新的表可能条件不够,需要用到left join关联其他表, 但是不能直接关联,否则报错:错误如下: update imim_gireqbillitems gi left join ...
- angular开发中对请求数据层的封装
代码地址如下:http://www.demodashi.com/demo/11481.html 一.本章节仅仅是对angular4项目开发中数据请求封装到model中 仅仅是在项目angular4项目 ...
- js可以关闭android页面上的键盘输入法
尝试让获取焦点的元素失去焦点,document.activeElement.blur() js实现焦点进入文本框内关闭输入法:imeMode2011-05-26 11:23要用到的东西: imeMod ...
- EMQ 学习---订阅$SYS主题,捕获客户端上下线消息
acl.config文件定义了可订阅$SYS主题的权限. {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]} ...
- python-简单函数小例子 单位转换
第一种方法def fahrenheit_converter(g): fahrenheit = g /1000 return str(fahrenheit) + 'kg' #调用函数g2kg = fah ...