1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
.TH "KDK_TIMER_SESET" 3 "Fri Sep 22 2023" "My Project" \" -*- nroff -*-
.ad l
.nh
.SH NAME
kdk_timer_reset \- 重置定时器时间至intervalms
.SH SYNOPSIS
.br
.PP
\fC#include <libkytimer\&.h>\fP
.br
.SS "Functions"
.SS "void kdk_timer_reset (size_t timerfd, unsigned int intervalms)"
.PP
重置定时器时间至intervalms,以毫秒为单位
.PP
\fBParameters\fP
.RS 4
\fItimerfd\fP 由kdk_timer_start返回的定时器ID
.br
\fIintervalms\fP 需要调整的时间间隔,以ms为单位
.RE
.PP
Link with \fI\-lkytimer\fP.
.SH "Detailed Description"
.PP
接口的主要功能是重置定时器时间至intervalms,以毫秒为单位
.SH EXAMPLES
.EX
#include <libkytimer.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
void func(char* comment)
{
char date[32] = {0};
time_t now;
time(&now);
if (ctime_r(&now , date))
date[strlen(date) - 1] = '\0';
printf("[%s]这是%s\n" , date , comment);
}
void stop(size_t* fdpoll)
{
printf("开始停止定时器\n");
for (int i = 0 ; i < 10 ; i ++)
{
kdk_timer_stop(fdpoll[i]);
}
}
int main()
{
assert(kdk_timer_init() == 0);
//测试1 -- 基本功能
size_t fdpoll[10] = {0};
// for (int i = 1 ; i <= 10 ; i ++)
// {
// char* data = (char*)malloc(10);
// assert(data);
// sprintf(data , "%d号" , i);
// fdpoll[i - 1] = kdk_timer_start(i * 1000 , (time_handler)func , KTIMER_PERIODIC , KTIMER_ABSOLUTE, (void*)data , 1);
// assert(fdpoll[i - 1]);
// }
kdk_timer_start(10000 , (time_handler)stop , KTIMER_SINGLESHOT , KTIMER_ABSOLUTE, (void*)fdpoll , 0);
sleep(11);
//测试3 -- 单次触发
printf("单次触发测试:\n");
kdk_timer_start(2000 , (time_handler)func , KTIMER_SINGLESHOT , KTIMER_ABSOLUTE, "2号" , 0);
sleep(5);
//测试2 -- 重置定时器时间
printf("修改时间测试:\n");
int persec = kdk_timer_start(1000 , (time_handler)func , KTIMER_PERIODIC , KTIMER_ABSOLUTE, "1号" , 0);
int sec3 = kdk_timer_start(3000 , (time_handler)func , KTIMER_SINGLESHOT , KTIMER_ABSOLUTE, "3号" , 0);
sleep(2);
kdk_timer_reset(sec3 , 4000);
printf("sec3 时钟已被重置为4000ms\n");
sleep(10);
printf("正在销毁定时器核心...\n");
kdk_timer_destroy();
return 0;
}
.SH "CONFORMING TO"
These functions are as per the withdrawn POSIX.1e draft specification.
The following functions are Linux extensions:
.BR kdk_timer_init (),
.BR kdk_timer_start (),
.BR kdk_timer_stop ()
and
.BR kdk_timer_destroy ().
.SH "SEE ALSO"
.BR kdk_timer_init (3),
.BR kdk_timer_start (3),
.BR kdk_timer_stop (3)
and
.BR kdk_timer_destroy (3).
.SH "Author"
.PP
Generated automatically by Doxygen for libkytimer.h from the source code\&.
|