20191001(12)RT-Thread 时钟管理 源码解读(1)创建部分 2023-08-17 17:35 392阅读 0赞 #### 目的 #### 1. 了解创建和初始化源码 -------------------- #### 正文 #### 根据阅读线程源码的经验,我直接开始阅读最核心的函数 \_rt\_timer\_init() /** * timer structure */ struct rt_timer { struct rt_object parent; /**< inherit from rt_object */ rt_list_t row[RT_TIMER_SKIP_LIST_LEVEL]; void (*timeout_func)(void *parameter); /**< timeout function */ void *parameter; /**< timeout function's parameter */ rt_tick_t init_tick; /**< timer timeout tick */ rt_tick_t timeout_tick; /**< timeout tick */ }; typedef struct rt_timer *rt_timer_t; static void _rt_timer_init(rt_timer_t timer, //静态定时器对象句柄 void (*timeout)(void *parameter), //超时回调函数 void *parameter,//传入参数 rt_tick_t time,//超时时间 rt_uint8_t flag)//定时器创建时的参数,支持的值包括单次定时、周期定时、 硬件定时器、软件定时器(可以用 “或” 关系取多个值) { int i; /* set flag */ timer->parent.flag = flag; /* set deactivated */ timer->parent.flag &= ~RT_TIMER_FLAG_ACTIVATED; timer->timeout_func = timeout; timer->parameter = parameter; timer->timeout_tick = 0; timer->init_tick = time; /* initialize timer list */ for (i = 0; i < RT_TIMER_SKIP_LIST_LEVEL; i++) { rt_list_init(&(timer->row[i])); //见 } } /** * @brief initialize a list * * @param l list to be initialized */ rt_inline void rt_list_init(rt_list_t *l) { l->next = l->prev = l; } 总体看来这部内容就是对于 rt\_timer 数据结构进行赋值操作,总体操作与线程部分一致不做细致讲解 -------------------- 初始化函数和创建函数 //function: rt_timer_create() /** * This function will create a timer * * @param name the name of timer * @param timeout the timeout function * @param parameter the parameter of timeout function * @param time the tick of timer * @param flag the flag of timer * * @return the created timer object */ rt_timer_t rt_timer_create(const char *name, //定时器名字 void (*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag) { struct rt_timer *timer; /* allocate a object */ //由系统分配一个定时器对象 timer = (struct rt_timer *)rt_object_allocate(RT_Object_Class_Timer, name); if (timer == RT_NULL) { return RT_NULL; } _rt_timer_init(timer, timeout, parameter, time, flag); return timer; } //rt_timer_init() /** * This function will initialize a timer, normally this function is used to * initialize a static timer object. * * @param timer the static timer object * @param name the name of timer * @param timeout the timeout function * @param parameter the parameter of timeout function * @param time the tick of timer * @param flag the flag of timer */ void rt_timer_init(rt_timer_t timer, //定时器对象的句柄(指针) const char *name, void (*timeout)(void *parameter), void *parameter, rt_tick_t time, rt_uint8_t flag) { /* timer check */ RT_ASSERT(timer != RT_NULL); /* timer object initialization */ rt_object_init((rt_object_t)timer, RT_Object_Class_Timer, name); _rt_timer_init(timer, timeout, parameter, time, flag); }
相关 ConcurrentHashMap源码解读 曾经研究过jkd1.5新特性,其中ConcurrentHashMap就是其中之一,其特点:效率比Hashtable高,并发性比hashmap好。结合了两者的特点。 集合是编 ゝ一纸荒年。/ 2021年09月07日 06:05/ 0 赞/ 386 阅读
相关 源码解读系列(二)EventBus3.1.1 1、EventBus的构造过程 使用EventBus的时候,首先要获取EventBus ![eventbus][] ![EventBus][] 构造方法是一个 雨点打透心脏的1/2处/ 2022年03月14日 08:56/ 0 赞/ 75 阅读
相关 jdk1.8 HashMap 源码解读 一,HashMap的中的概述 在JDK1.8之前,HashMap中中中采用数组+链表实现,即使用链表处理冲突,同一散列值的节点都存储在一个链表里。但是当位于一个桶 深碍√TFBOYSˉ_/ 2022年04月03日 09:58/ 0 赞/ 158 阅读
相关 Derek解读Bytom源码-孤块管理 本章介绍bytom代码孤块管理 > 作者使用MacOS操作系统,其他平台也大同小异 > > Golang Version: 1.8 孤块介绍 什么是孤块 当节 淡淡的烟草味﹌/ 2022年04月18日 02:40/ 0 赞/ 32 阅读
相关 源码通透-spring-AOP-1-AOP源码解读 源码通透-spring-AOP-1-AOP源码解读 -------------------- spring源码版本:spring5.0 JDK版本: 1.8 我 妖狐艹你老母/ 2022年04月25日 03:04/ 0 赞/ 118 阅读
相关 ThreadLocal源码解读 1. 背景 ThreadLocal源码解读,网上面早已经泛滥了,大多比较浅,甚至有的连基本原理都说的很有问题,包括百度搜索出来的第一篇高访问量博文,说ThreadLoca 喜欢ヅ旅行/ 2022年05月08日 01:52/ 0 赞/ 158 阅读
相关 Wei框架源码解读(1) 一、Wei框架 Wei框架是一个简单的小应用框架,其中整合了spring,spring MVC,mybatis的框架,适合简单的应用的开发和扩展,这样可以快速的进行开 青旅半醒/ 2022年05月26日 10:27/ 0 赞/ 47 阅读
相关 disconf源码解读(1) 使用disconf的时候,需要在classpath中添加一个配置文件:disconf.properties 是否使用远程配置文件 true(默认)会从远程获取配置 怼烎@/ 2022年07月12日 12:45/ 0 赞/ 100 阅读
相关 Spring5源码 - 04 invokeBeanFactoryPostProcessors 源码解读_1 文章目录 Pre refresh() Spring的设计 源码验证 ![在这里插入图片描述][watermark_type_ZmFuZ3poZW ﹏ヽ暗。殇╰゛Y/ 2022年12月07日 15:07/ 0 赞/ 66 阅读
相关 20191001(12)RT-Thread 时钟管理 源码解读(1)创建部分 目的 1. 了解创建和初始化源码 -------------------- 正文 根据阅读线程源码的经验,我直接开始阅读最核心的函数 \_rt\_timer\ 朱雀/ 2023年08月17日 17:35/ 0 赞/ 393 阅读
还没有评论,来说两句吧...