Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/scPublic

timer

Directory actions

More options

Directory actions

More options

Latest commit

 

History

History

timer

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Overview

  • Hashed timing wheel implementation.
  • Provides fast cancel(O(1)) and poll operations compared to a priority queue.
  • Timers in the same hash slot are not ordered between each other. So, basically
    this data structure trades accuracy for performance. Schedule a timer for
    10000ms and another for 10001ms and you might see 10001ms timer expires
    just before 10000ms timer. Default tick is 16 ms, so, timers in the same 16ms
    interval may expire out of order.

Usage

#include"sc_timer.h"#include<errno.h>#include<stdio.h>#include<time.h>uint64_ttime_ms();voidsleep_ms(uint64_tmilliseconds);voidcallback(void*arg,uint64_ttimeout,void*data){structsc_timer*timer=arg;char*timer_name=data;printf("timeout : %zu, data : %s \n",timeout,timer_name);// Schedule backsc_timer_add(timer,"timer1",1000);}intmain(intargc,char*argv[]){uint64_tnext_timeout;structsc_timertimer;sc_timer_init(&timer,time_ms());sc_timer_add(&timer,"timer1",1000);while (true) {next_timeout=sc_timer_timeout(&timer,time_ms(),&timer,callback);sleep_ms(next_timeout);    }return0;}

[8]ページ先頭

©2009-2025 Movatter.jp