zebra/quagga线程分析

本文介绍了一种线程管理机制,通过不同功能的链表(如读取、写入、定时器等)来组织线程,实现了线程的有效调度与资源的高效利用。线程在运行前后会在不同的链表间迁移,以确保系统的稳定运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/* 线程按照不同的功能进行分类。有6条双链,分别表示不同类型的线程。将要运行的时候,
* 就从不同的链表中取出,添加到ready链表中,运行完成之后,将线程结构体清空放到
* unuse链表中。一般利用现有unuse链表的资源,根据功能添加在不同的链表中。
* 只有当线程结构体都使用了,即ununse链表空的时候,才重新申请新的空间 */
struct thread_master { struct thread_list read; struct thread_list write; struct thread_list timer; struct thread_list event; struct thread_list ready; struct thread_list unuse; fd_set readfd; fd_set writefd; fd_set exceptfd; unsigned long alloc; }; /* thread_list结构体用于记录每种链表的信息。head指向双链表头,tail指向双链表尾
* count记录当前链表中有多少个节点 */
struct thread_list { struct thread *head; struct thread *tail; int count; }; /* 单个线程的数据,按照功能不同包含在不同的thread_list结构中。
* 线程调用完成之后,将内部的信息清空,添加到unuse链表中 */
struct thread { thread_type type; thread_type add_type; struct thread *next; struct thread *prev; struct thread_master *master; int (*func) (struct thread *); /* 线程中保存的处理函数 */ void *arg; /* 线程中保存的参数 */ union {   int val;   int fd;   struct timeval sands; } u; RUSAGE_T ru; struct cpu_thread_history *hist; char* funcname; };

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值