1 Star 1 Fork 0

jxva / jv-timer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

A modern, high performance, efficient task timer based rbtree using ANSI C

A modern, high performance, efficient task timer using ANSI C, based Red Black Tree (rbtree), you may be also see []https://github.com/jxva/jv-rbtree

Features

  • No dependence
  • ~150 LOC
  • Use efficient algorithms based rbtree

Getting Started

jv_timer_main.c

#include <jv_timer.h>
#include <sys/time.h> /* gettimeofday */
#include <unistd.h>   /* usleep */

extern volatile jv_msec_t jv_current_msec;

static jv_msec_t jv_time_update(void) {

    time_t sec;
    jv_uint_t msec;
    struct timeval tv;

    (void)gettimeofday(&tv, NULL);

    sec = tv.tv_sec;
    msec = tv.tv_usec / 1000;

    jv_current_msec = (jv_msec_t)sec * 1000 + msec;

    return jv_current_msec;
}

void timer_test1(void *arg) {
  printf("timer_test1()\n");
}

void timer_test2(void *arg) {
  printf("timer_test2()\n");
}

void timer_test3(void *arg) {
  printf("timer_test3()\n");
  usleep(100);
}

void sig_int(int signo) {
  puts("Exit");
  exit(0);
}

int main(int argc, char *argv[]) {
  jv_timer_t *timer;

  signal(SIGINT, sig_int);

  timer = jv_timer_create();

  jv_time_update();

  if (!jv_timer_add(timer, 0, 1 * 1000L, timer_test1, NULL)) {
    printf("tmr_create(test1) failed\n");
    exit(1);
  }

  if (!jv_timer_add(timer, 2 * 1000L, 0, timer_test2, NULL)) {
    printf("tmr_create(test2) failed\n");
    exit(1);
  }

  if (!jv_timer_add(timer, 0, 3 * 1000L, timer_test3, NULL)) {
    printf("tmr_create(test3) failed\n");
    exit(1);
  }

  while (1) {
    printf("jv_timer_mstimeout:%lu\n", jv_timer_mstimeout(timer));
    jv_time_update();
    jv_timer_run(timer);
    usleep(1000 * 1000L);
  }

  jv_timer_destroy(timer);
  return 0;
}

Build

$ make

Run

$ ./jv_timer_main

Api References

TODO

License

This project is under MIT License. See the LICENSE file for the full license text.

MIT License Copyright (c) 2018 Zane Chiang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

A modern, high performance, efficient timer based rbtree using ANSI C 展开 收起
C
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
C
1
https://gitee.com/jxva/jv-timer.git
git@gitee.com:jxva/jv-timer.git
jxva
jv-timer
jv-timer
master

搜索帮助