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 ...
随机推荐
- Spark Streaming的PIDRateEstimator与backpressure
PIDRateEstimator是Spark Streaming用来实现backpressure的关键组件. 看了一些博客文章,感觉对它的解释都没有说到要点,还是自己来研究一下比较好. 首先,需要搞清 ...
- leetcode 282. 给表达式添加运算符
给定一个仅包含0-9的字符串和一个目标值,返回在数字之间添加了二元运算符(不是一元的) +.-或*之后所有能得到目标值的情况. 例如: "123", 6 -> [" ...
- OC中数组的使用方法
#import <Foundation/Foundation.h> int main(int argc, const char * argv[]) { // 创建数组 NS ...
- [Algorithm] Fibonacci problem by using Dynamic programming
vThere are three ways to solve Fibonacci problem Recursion Memoize Bottom-up 'First Recursion approa ...
- 在表单里面检查用户名是否存javascript
function CheckUser(fn) { $.get("/Pages/Handler/CheckExistHander.ashx", { "txt_UserNo& ...
- Junit核心——测试集(TestSuite)
关于测试集,实质就是包含若干个测试类的集合,通过一个具体的实例,让我们来了解一下Junit的测试集 package org.yezi.junit; public class Calcaute { pu ...
- nginx安装说明
下载地址:http://nginx.org/en/download.html 安装版本:1.10.0 安装配置如下: /etc/nginx 目录 /home/nginx目录 --prefix=/hom ...
- MyCAT学习总结
MyCAT介绍 简单的说,MyCAT就是: 一个彻底开源的,面向企业应用开发的“大数据库集群” 支持事务.ACID(指数据库事务正确执行的四个基本要素的缩写.包含:原子性(Atomicity).一 ...
- SQL如何将EXCEL导入到SQL数据库
1 新建一个EXCEL工作表,注意默认有三个工作簿,我们只在Sheet1中创建几个字段并存储若干值保存为TEST.xls 2运行Excel to MySQL软件,注意Sourece和Destinati ...
- 服务器变量 超级全局数组$_SERVER (附加超简单表单与html5表单属性)
001.html <html> <head><title>user log</title> <meta http-equiv="cont ...