基于小根堆的定时管理器

定时器的实现依赖的是CPU时钟中断,时钟中断的精度就决定定时器精度的极限。一个时钟中断源如何实现多个定时器呢?对于内核,简单来说就是用特定的数据结构管理众多的定时器,在时钟中断处理中判断哪些定时器超时,然后执行超时处理动作。而用户空间程序不直接感知CPU时钟中断,通过感知内核的信号、IO事件、调度,间接依赖时钟中断。这里用小根堆来实现一个用户态的定时管理器….

参考文章:

  1. Linux C/C++定时器的实现原理和使用方法
  2. C时间堆
  3. c实现的几种定时器

待优化点

  1. 精准的定时系统。(setitimer() or…..?)
  2. 动态管理堆大小。

原理

heap_time.h

#ifndef _HEAP_TIME_
#define _HEAP_TIME_
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<time.h>

typedef struct task_param
{
    int         uid;
    time_t      tt;
} task_param;

typedef struct task_unit
{
    time_t      expire;                             /* 定时器设置绝对时间 */
    int         delay_time;                         /* 设定延迟时间 */
    int         uuid;                               /* 任务标识符 */
    void        (*task_func)(void *);               /* 定时回调函数 */
    struct      task_param* client_alarm_data;      /* 回调函数参数 */
} task_unit;

typedef struct heap_timer
{
    struct task_unit**  heap_array;                 /* 定时器指针数组 */
    int                 capacity;                   /* 定时器的最大容量 */
    int                 cur_num;                    /* 当前定时管理器上得定时器个数 */
} heap_timer;

heap_timer tmanager1;

int init_heap_time(heap_timer* tmanager, int cap);
int add_timer(heap_timer *tmanager, int timeout, int uuid);
void alarm_handler(int sig);
#endif

heap_time.c

#include"heap_timer.h"

char* time_t2string(time_t intime)
{
    char* strtime = (char *)malloc(sizeof(char)*20);
#if 0
    strftime(strtime, 20, "%Y-%m-%d %H:%M:%S", localtime(&intime));
#endif
    strftime(strtime, 20, "%H:%M:%S", localtime(&intime));
    return strtime;
}

void task_func(void* param)
{
    task_param* taskparam = (task_param*)param;
    printf("************************************************************************\n");
    printf("uuid [%d] the timer begin time: [%s]\n",taskparam->uid,time_t2string(taskparam->tt));
    printf("************************************************************************\n");
}

/* 堆状态打印 */
void print_heap_time(heap_timer* tmanager)
{
    int i = 0;
    time_t cur = time(NULL);
    printf("------------------------------------------------------------------------\n");
    printf("func:[%s] timer numbers:[%d] now time:[%s]\n",__func__,tmanager->cur_num,time_t2string(cur));
    for(;i<tmanager->cur_num;i++)
    {
        if(tmanager->heap_array[i])
        printf("order:[%d] uuid:[%d] begin time:[%s] delay time:[%d] dealtime:[%s]\n",i,tmanager->heap_array[i]->uuid, \
        time_t2string((time_t)(tmanager->heap_array[i]->expire-tmanager->heap_array[i]->delay_time)), \
        tmanager->heap_array[i]->delay_time,time_t2string((time_t)tmanager->heap_array[i]->expire));
    }
    printf("------------------------------------------------------------------------\n");
}
/* 下滤堆调整 */
void percolate_down(heap_timer* tmanager, int hole)
{
    int child = 0;
    for(;((hole*2+1) <= (tmanager->cur_num-1)); hole = child)
    {
        child = hole * 2 + 1;
        //这里找出当前节点最小儿子节点
        if ( (child < (tmanager->cur_num-1)) 
            && (tmanager->heap_array[child+1]->expire) 
                < tmanager->heap_array[child]->expire )
        {
            ++child;
        }
        //比较待删除节点和最小儿子节点,大于就交换
        if(tmanager->heap_array[child]->expire < tmanager->heap_array[hole]->expire)
        {
            //这里的交换其实该用内存拷贝比较好
            task_unit* tmp_heap_timer = tmanager->heap_array[hole];
            tmanager->heap_array[hole] = tmanager->heap_array[child];
            tmanager->heap_array[child] = tmp_heap_timer;
        }
        else
        {
            break;
        }
    }
}
/* 将堆空间增大一倍 */
int increase_heap(heap_timer* tmanager)
{
    printf("increase_heap\n");
    task_unit** temp = (task_unit**)
            malloc(2*tmanager->capacity*sizeof(task_unit*));

    int i = 0;
    for(; i<2*tmanager->capacity;++i)
    {
        temp[i] = NULL;
    }
    if(!temp)
    {
        return -1;
    }
    tmanager->capacity = 2 * tmanager->capacity;
    for(i=0;i<tmanager->cur_num;++i)
    {
        temp[i] = tmanager->heap_array[i];
        tmanager->heap_array[i] = NULL;
    }
    free(tmanager->heap_array);
    tmanager->heap_array = temp;
    return 0;
}
/* 减小堆空间(待修改,未使用) */
int reduce_resize(heap_timer* tmanager)
{
    printf("reduce_resize\n");
    task_unit** temp = (task_unit**)
            malloc(0.75*tmanager->capacity*sizeof(task_unit*));

    int i = 0;
    for(; i<2*tmanager->capacity;++i)
    {
        temp[i] = NULL;
    }
    if(!temp)
    {
        return -1;
    }
    tmanager->capacity = 0.75 * tmanager->capacity;
    for(i=0;i<tmanager->cur_num;++i)
    {
        temp[i] = tmanager->heap_array[i];
        tmanager->heap_array[i] = NULL;
    }
    free(tmanager->heap_array);
    tmanager->heap_array = temp;
    return 0;
}
/* 初始化一个小根堆空间 */
int init_heap_time(heap_timer* tmanager, int cap)
{
    tmanager->capacity = cap;
    tmanager->cur_num = 0;
    tmanager->heap_array = (task_unit**)malloc(cap * sizeof(task_unit*));
    if(NULL == tmanager->heap_array)
    {
        printf("init heap error\n");
    }
    int i = 0;
    for(;i<cap;++i)
    {
        tmanager->heap_array[i] = NULL;
    }
    printf("[%s] complete...\n",__func__);
    return 0;
}
/* 添加定时任务到堆空间 */
int add_timer(heap_timer *tmanager, int timeout, int uuid)
{
    if(!tmanager || timeout <= 0)
    {
        return -1;
    }
    if(tmanager->cur_num >= tmanager->capacity)
    {
        printf("Insufficient heap space,Redistribution....\n");
        increase_heap(tmanager);
    }

    int hole = tmanager->cur_num++;
    int parent = 0;
    task_unit* timer = (task_unit*)malloc(sizeof(task_unit));
    time_t tt = time(NULL);
    timer->expire = (int)tt + timeout;
    timer->delay_time = timeout;
    timer->uuid = uuid;
    timer->client_alarm_data = (task_param*)malloc(sizeof(task_param*));
    timer->client_alarm_data->tt = tt;
    timer->client_alarm_data->uid = uuid;
    timer->task_func = task_func;

    for(; hole>0; hole=parent)
    {
        parent = (hole-1)/2;
        if(tmanager->heap_array[parent]->expire <= timer->expire)
        {
            break;
        }
        tmanager->heap_array[hole] = tmanager->heap_array[parent];
    }
    tmanager->heap_array[hole] = timer;
    printf("[%s] uuid:[%d] begin time:[%s] delay_time:[%d] add over...\n",__func__ , tmanager->heap_array[hole]->uuid, \
    time_t2string(tt), tmanager->heap_array[hole]->delay_time);
    return 0;
}
/* 判断堆空间是否为0 */
int empty(heap_timer* tmanager)
{
    return tmanager->cur_num == 0;
}
/* 定时时间到,启动任务 */
int pop_timer(heap_timer* tmanager)
{
    if(empty(tmanager))
    {
        printf("[%s]empty cur size\n",__func__);
        return -1;
    }
    if(tmanager->heap_array[0])
    {
        printf("%s...\n",__func__);
        free(tmanager->heap_array[0]);
        tmanager->heap_array[0] = NULL;
        tmanager->heap_array[0] = tmanager->heap_array[--tmanager->cur_num];
        percolate_down(tmanager, 0);
        //free(tmanager->heap_arry[tmanager->cur_num]);
        //tmanager->heap_arry[tmanager->cur_num] = NULL;
    }
    return 0;
}

/* 心跳检测函数 */
void tick(heap_timer* tmanager)
{
    task_unit *tmp = tmanager->heap_array[0];
    time_t cur = time(NULL);
    while(!empty(tmanager))
    {
        if(!tmp)
        {
            break;
        }
        if(tmp->expire > cur)
        {
            printf("%s check no task comming...\n",__func__);
            break;
        }
        if(tmanager->heap_array[0]->task_func)
        {
            printf("%s task comming begin working...\n",__func__);
            print_heap_time(tmanager);
            tmanager->heap_array[0]->task_func(tmanager->heap_array[0]->client_alarm_data);
        }
        pop_timer(tmanager);
        print_heap_time(tmanager);
    }
}
/* 信号处理函数 */
void alarm_handler(int sig)
{
    tick(&tmanager1);
    if(tmanager1.cur_num > 0)      /* 当有任务存在时 */
    {
        alarm(tmanager1.heap_array[0]->expire-time(NULL));
    }
    else
    {
        printf("no task!\n");
        alarm(2);
    }
}

main.c

#include"heap_timer.h"
#include<signal.h>

int main()
{
    printf("Start building heaps....\n");
    init_heap_time(&tmanager1, 6);

    add_timer( &tmanager1, 90, 1 );
    add_timer( &tmanager1, 80, 2 );
    add_timer( &tmanager1, 70, 3 );
    add_timer( &tmanager1, 60, 4 );
    add_timer( &tmanager1, 50, 5 );

    signal( SIGALRM, alarm_handler );

    time_t tt = time(NULL);
    printf("curr time:%s\n", ctime(&tt));
    alarm( tmanager1.heap_array[0]->expire - time(NULL) );

    int i = 6;
    int j = 6;
    while(i)
     {
        sleep(10);
        printf("********************%d*******************\n",--i);
        add_timer( &tmanager1, i*i,  j++);
    }
    sleep(60);
    add_timer( &tmanager1, 40 , j++);
    add_timer( &tmanager1, 30 , j++);
    add_timer( &tmanager1, 20 , j++);
    add_timer( &tmanager1, 10 , j++);
    add_timer( &tmanager1, 7 , j++);

    while(1)
        sleep(5);
 
    return 0;
}

测试

hello@world:/mnt/shared$ ./a.out 
Start building heaps....
[init_heap_time] complete...
[add_timer] uuid:[1] begin time:[21:50:24] delay_time:[90] add over...
[add_timer] uuid:[2] begin time:[21:50:24] delay_time:[80] add over...
[add_timer] uuid:[3] begin time:[21:50:24] delay_time:[70] add over...
[add_timer] uuid:[4] begin time:[21:50:24] delay_time:[60] add over...
[add_timer] uuid:[5] begin time:[21:50:24] delay_time:[50] add over...
curr time:Sat Mar 23 21:50:24 2019

[add_timer] uuid:[6] begin time:[21:50:34] delay_time:[36] add over...
********************5*******************
Insufficient heap space,Redistribution....
resize heap_timer
[add_timer] uuid:[7] begin time:[21:50:44] delay_time:[25] add over...
********************4*******************
[add_timer] uuid:[8] begin time:[21:50:54] delay_time:[16] add over...
********************3*******************
[add_timer] uuid:[9] begin time:[21:51:04] delay_time:[9] add over...
********************2*******************
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[9] now time:[21:51:14]
order:[0] uuid:[7] begin time:[21:50:44] delay time:[25] dealtime:[21:51:09]
order:[1] uuid:[8] begin time:[21:50:54] delay time:[16] dealtime:[21:51:10]
order:[2] uuid:[6] begin time:[21:50:34] delay time:[36] dealtime:[21:51:10]
order:[3] uuid:[9] begin time:[21:51:04] delay time:[9] dealtime:[21:51:13]
order:[4] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[5] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[6] uuid:[5] begin time:[21:50:24] delay time:[50] dealtime:[21:51:14]
order:[7] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
order:[8] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
------------------------------------------------------------------------
************************************************************************
uuid [7] the timer begin time: [21:50:44]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[8] now time:[21:51:14]
order:[0] uuid:[8] begin time:[21:50:54] delay time:[16] dealtime:[21:51:10]
order:[1] uuid:[9] begin time:[21:51:04] delay time:[9] dealtime:[21:51:13]
order:[2] uuid:[6] begin time:[21:50:34] delay time:[36] dealtime:[21:51:10]
order:[3] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[4] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[5] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[6] uuid:[5] begin time:[21:50:24] delay time:[50] dealtime:[21:51:14]
order:[7] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[8] now time:[21:51:14]
order:[0] uuid:[8] begin time:[21:50:54] delay time:[16] dealtime:[21:51:10]
order:[1] uuid:[9] begin time:[21:51:04] delay time:[9] dealtime:[21:51:13]
order:[2] uuid:[6] begin time:[21:50:34] delay time:[36] dealtime:[21:51:10]
order:[3] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[4] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[5] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[6] uuid:[5] begin time:[21:50:24] delay time:[50] dealtime:[21:51:14]
order:[7] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
************************************************************************
uuid [8] the timer begin time: [21:50:54]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[7] now time:[21:51:14]
order:[0] uuid:[6] begin time:[21:50:34] delay time:[36] dealtime:[21:51:10]
order:[1] uuid:[9] begin time:[21:51:04] delay time:[9] dealtime:[21:51:13]
order:[2] uuid:[5] begin time:[21:50:24] delay time:[50] dealtime:[21:51:14]
order:[3] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[4] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[5] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[6] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[7] now time:[21:51:14]
order:[0] uuid:[6] begin time:[21:50:34] delay time:[36] dealtime:[21:51:10]
order:[1] uuid:[9] begin time:[21:51:04] delay time:[9] dealtime:[21:51:13]
order:[2] uuid:[5] begin time:[21:50:24] delay time:[50] dealtime:[21:51:14]
order:[3] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[4] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[5] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[6] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
************************************************************************
uuid [6] the timer begin time: [21:50:34]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[6] now time:[21:51:14]
order:[0] uuid:[9] begin time:[21:51:04] delay time:[9] dealtime:[21:51:13]
order:[1] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[2] uuid:[5] begin time:[21:50:24] delay time:[50] dealtime:[21:51:14]
order:[3] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
order:[4] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[5] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[6] now time:[21:51:14]
order:[0] uuid:[9] begin time:[21:51:04] delay time:[9] dealtime:[21:51:13]
order:[1] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[2] uuid:[5] begin time:[21:50:24] delay time:[50] dealtime:[21:51:14]
order:[3] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
order:[4] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[5] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
------------------------------------------------------------------------
************************************************************************
uuid [9] the timer begin time: [21:51:04]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[5] now time:[21:51:14]
order:[0] uuid:[5] begin time:[21:50:24] delay time:[50] dealtime:[21:51:14]
order:[1] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[2] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[3] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
order:[4] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[5] now time:[21:51:14]
order:[0] uuid:[5] begin time:[21:50:24] delay time:[50] dealtime:[21:51:14]
order:[1] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[2] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[3] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
order:[4] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
------------------------------------------------------------------------
************************************************************************
uuid [5] the timer begin time: [21:50:24]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[4] now time:[21:51:14]
order:[0] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[1] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[2] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[3] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[4] now time:[21:51:14]
order:[0] uuid:[4] begin time:[21:50:24] delay time:[60] dealtime:[21:51:24]
order:[1] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[2] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[3] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
************************************************************************
uuid [4] the timer begin time: [21:50:24]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[3] now time:[21:51:14]
order:[0] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[1] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
order:[2] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[3] now time:[21:51:14]
order:[0] uuid:[3] begin time:[21:50:24] delay time:[70] dealtime:[21:51:34]
order:[1] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
order:[2] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
------------------------------------------------------------------------
************************************************************************
uuid [3] the timer begin time: [21:50:24]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[2] now time:[21:51:14]
order:[0] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[1] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[2] now time:[21:51:14]
order:[0] uuid:[2] begin time:[21:50:24] delay time:[80] dealtime:[21:51:44]
order:[1] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
************************************************************************
uuid [2] the timer begin time: [21:50:24]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[1] now time:[21:51:14]
order:[0] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[1] now time:[21:51:14]
order:[0] uuid:[1] begin time:[21:50:24] delay time:[90] dealtime:[21:51:54]
------------------------------------------------------------------------
************************************************************************
uuid [1] the timer begin time: [21:50:24]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[0] now time:[21:51:14]
------------------------------------------------------------------------
no task!
[add_timer] uuid:[10] begin time:[21:51:14] delay_time:[4] add over...
********************1*******************
tick check no task comming...
[add_timer] uuid:[11] begin time:[21:51:16] delay_time:[1] add over...
********************0*******************
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[2] now time:[21:51:18]
order:[0] uuid:[11] begin time:[21:51:16] delay time:[1] dealtime:[21:51:17]
order:[1] uuid:[10] begin time:[21:51:14] delay time:[4] dealtime:[21:51:18]
------------------------------------------------------------------------
************************************************************************
uuid [11] the timer begin time: [21:51:16]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[1] now time:[21:51:18]
order:[0] uuid:[10] begin time:[21:51:14] delay time:[4] dealtime:[21:51:18]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[1] now time:[21:51:18]
order:[0] uuid:[10] begin time:[21:51:14] delay time:[4] dealtime:[21:51:18]
------------------------------------------------------------------------
************************************************************************
uuid [10] the timer begin time: [21:51:14]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[0] now time:[21:51:18]
------------------------------------------------------------------------
no task!
[add_timer] uuid:[12] begin time:[21:51:18] delay_time:[40] add over...
[add_timer] uuid:[13] begin time:[21:51:18] delay_time:[30] add over...
[add_timer] uuid:[14] begin time:[21:51:18] delay_time:[20] add over...
[add_timer] uuid:[15] begin time:[21:51:18] delay_time:[10] add over...
[add_timer] uuid:[16] begin time:[21:51:18] delay_time:[7] add over...
tick check no task comming...
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[5] now time:[21:51:25]
order:[0] uuid:[16] begin time:[21:51:18] delay time:[7] dealtime:[21:51:25]
order:[1] uuid:[15] begin time:[21:51:18] delay time:[10] dealtime:[21:51:28]
order:[2] uuid:[13] begin time:[21:51:18] delay time:[30] dealtime:[21:51:48]
order:[3] uuid:[12] begin time:[21:51:18] delay time:[40] dealtime:[21:51:58]
order:[4] uuid:[14] begin time:[21:51:18] delay time:[20] dealtime:[21:51:38]
------------------------------------------------------------------------
************************************************************************
uuid [16] the timer begin time: [21:51:18]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[4] now time:[21:51:25]
order:[0] uuid:[15] begin time:[21:51:18] delay time:[10] dealtime:[21:51:28]
order:[1] uuid:[14] begin time:[21:51:18] delay time:[20] dealtime:[21:51:38]
order:[2] uuid:[13] begin time:[21:51:18] delay time:[30] dealtime:[21:51:48]
order:[3] uuid:[12] begin time:[21:51:18] delay time:[40] dealtime:[21:51:58]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[4] now time:[21:51:25]
order:[0] uuid:[15] begin time:[21:51:18] delay time:[10] dealtime:[21:51:28]
order:[1] uuid:[14] begin time:[21:51:18] delay time:[20] dealtime:[21:51:38]
order:[2] uuid:[13] begin time:[21:51:18] delay time:[30] dealtime:[21:51:48]
order:[3] uuid:[12] begin time:[21:51:18] delay time:[40] dealtime:[21:51:58]
------------------------------------------------------------------------
************************************************************************
uuid [15] the timer begin time: [21:51:18]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[3] now time:[21:51:25]
order:[0] uuid:[14] begin time:[21:51:18] delay time:[20] dealtime:[21:51:38]
order:[1] uuid:[12] begin time:[21:51:18] delay time:[40] dealtime:[21:51:58]
order:[2] uuid:[13] begin time:[21:51:18] delay time:[30] dealtime:[21:51:48]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[3] now time:[21:51:25]
order:[0] uuid:[14] begin time:[21:51:18] delay time:[20] dealtime:[21:51:38]
order:[1] uuid:[12] begin time:[21:51:18] delay time:[40] dealtime:[21:51:58]
order:[2] uuid:[13] begin time:[21:51:18] delay time:[30] dealtime:[21:51:48]
------------------------------------------------------------------------
************************************************************************
uuid [14] the timer begin time: [21:51:18]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[2] now time:[21:51:25]
order:[0] uuid:[13] begin time:[21:51:18] delay time:[30] dealtime:[21:51:48]
order:[1] uuid:[12] begin time:[21:51:18] delay time:[40] dealtime:[21:51:58]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[2] now time:[21:51:25]
order:[0] uuid:[13] begin time:[21:51:18] delay time:[30] dealtime:[21:51:48]
order:[1] uuid:[12] begin time:[21:51:18] delay time:[40] dealtime:[21:51:58]
------------------------------------------------------------------------
************************************************************************
uuid [13] the timer begin time: [21:51:18]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[1] now time:[21:51:25]
order:[0] uuid:[12] begin time:[21:51:18] delay time:[40] dealtime:[21:51:58]
------------------------------------------------------------------------
tick task comming begin working...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[1] now time:[21:51:25]
order:[0] uuid:[12] begin time:[21:51:18] delay time:[40] dealtime:[21:51:58]
------------------------------------------------------------------------
************************************************************************
uuid [12] the timer begin time: [21:51:18]
************************************************************************
pop_timer...
------------------------------------------------------------------------
func:[print_heap_time] timer numbers:[0] now time:[21:51:25]
------------------------------------------------------------------------
no task!
no task!
no task!
no task!
no task!
no task!
no task!
no task!
no task!
no task!
no task!
no task!
^C
hello@world:/mnt/shared$

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据