代码拉取完成,页面将自动刷新
同步操作将从 David Hu/MultiTimer 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "multi_timer.h"
#include <stdio.h>
/* Timer handle list head. */
static multi_timer_t* p_timer_list_ = NULL; // 全局指针变量
/* Timer tick */
static platform_ticks_interface_t platformTicksFunction = NULL;
int multi_timer_install_ticks(platform_ticks_interface_t ticks_func) {
platformTicksFunction = ticks_func;
return 0;
}
int multi_timer_start(multi_timer_t* timer, uint64_t timing, multi_timer_callback_t callback, void* user_data) {
if (!timer || !callback ) {
return -1;
}
multi_timer_t** p_next_timer_pointer_addr = &p_timer_list_;
/* Remove the existing target timer. */
for (; *p_next_timer_pointer_addr; p_next_timer_pointer_addr = &(*p_next_timer_pointer_addr)->next) {
if (timer == *p_next_timer_pointer_addr) {
*p_next_timer_pointer_addr = timer->next; /* remove from list */
break;
}
}
/* Init timer. */
timer->deadline = platformTicksFunction() + timing;
timer->callback = callback;
timer->user_data = user_data;
/* Insert timer. */
// 前插法
for (p_next_timer_pointer_addr = &p_timer_list_;; p_next_timer_pointer_addr = &(*p_next_timer_pointer_addr)->next) {
if (!*p_next_timer_pointer_addr) {
timer->next = NULL;
*p_next_timer_pointer_addr = timer;
//printf("header,timer:%p\r\n", timer);
break;
}
if (timer->deadline < (*p_next_timer_pointer_addr)->deadline) {
timer->next = *p_next_timer_pointer_addr;
*p_next_timer_pointer_addr = timer;
//printf("timer:%p\r\n", timer);
break;
}
}
return 0;
}
int multi_timer_stop(multi_timer_t* timer) {
multi_timer_t** p_next_timer_pointer_addr = &p_timer_list_;
/* Find and remove timer. */
for (; *p_next_timer_pointer_addr; p_next_timer_pointer_addr = &(*p_next_timer_pointer_addr)->next) {
multi_timer_t* entry = *p_next_timer_pointer_addr;
if (entry == timer) {
*p_next_timer_pointer_addr = timer->next;
break;
}
}
return 0;
}
int multi_timer_yield(void) {
multi_timer_t* entry = p_timer_list_;
for (; entry; entry = entry->next) {
/* Sorted list, just process with the front part. */
if (platformTicksFunction() < entry->deadline) {
return (int)(entry->deadline - platformTicksFunction());
}
/* remove expired timer from list */
p_timer_list_ = entry->next;
/* call callback */
if (entry->callback) {
entry->callback(entry, entry->user_data);
}
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。