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 ...
随机推荐
- centos关于vsftpd的配置、配置说明及常见问题
一.安装vsftpd 安装yum install -y vsftpd 开机启动 chkconfig vsftpd on 启动 service vsftpd start 加入防火墙 vi /etc/sy ...
- 绘制函数y=(x^2-2x+1)/(x^2+x+2)的曲线
代码: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Type ...
- python贪吃蛇
代码地址如下:http://www.demodashi.com/demo/13335.html 一.先展示python贪吃蛇效果 二.操作说明 按键 功能 UP 向上移动 DOWN 向下移动 LEFT ...
- JavaScript经常使用代码段
把例如以下代码增加<body>区域中: 后退 前进 <!--<input type="button" value="后退" onClic ...
- oracle将一个表中字段的值赋值到另一个表中字段(批量)
面积表中数据错误,现将面积表中的sfmj字段的值改为居民信息表中匹配字段的值 update (select s.name name1,s2.name name2 from simple s,simpl ...
- pip换国内源
pip换国内源 1.国内常用源 阿里云 http://mirrors.aliyun.com/pypi/simple/ 中国科技大学 https://pypi.mirrors.ustc.edu. ...
- elem.attr()无法正确判断checkbox是否选中
本篇文章由:http://xinpure.com/elem-attr-does-not-correctly-determine-whether-the-checkbox-is-selected/ 关于 ...
- 【转贴】J2EE中的13种技术规范
J2EE平台由一整套服务(Services).应用程序接口(APIs)和协议构成,它对开发基于Web的多层应用提供了功能支持,下面对J2EE中的13种技术规范进行简单的描述(限于篇幅,这里只能进行简单 ...
- REMOTE HOST IDENTIFICATION HAS CHANGED问题的解决方式
好久没更新博客园. 这段没更新博客的时间内收获了很多,所以更新下博客来整理.记录这段时间内学到的内容. 最近腾讯云服务器欠费停机了,所以趁着缴费.趁着心血来潮就……重装了云系统.结果在进行远程ssh连 ...
- css定位positon
值 描述 absolute 生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位. 元素的位置通过 "left", "top", " ...