?? periodic_handler.c
字號:
/* vim: set ts=4: *//* * Written by Der Herr Hofrat <der.herr@hofr.at> * Copyright Der Herr Hofrat * Released under GPL V2 *//* * call a user-space allplication signal handler under control of an rt-clock * source (periodic rt-thread actually). */#include <stdio.h>#include <rtlinux_signal.h>#define PERIOD 50000 /* period in nanoseconds */void my_handler(int);struct rtlinux_sigaction sig, oldsig;long long rt_count=0;int main(void) { int i=0; sig.sa_handler = my_handler; sig.sa_flags = RTLINUX_SA_PERIODIC; sig.sa_period = PERIOD; if(rtlinux_sigaction(RTLINUX_SIGTIMER0,&sig,&oldsig)) { fprintf(stderr,"errore creating signal handler\n"); return -1; } /* keep the handler active for 10 seconds then reset it and exit * note that the loop takes longer than one second as the loop * time is sleep(1) + loop overhead - you actually can "measure" * the loop overhead by running the same handler for 10 seconds * without the while loop and compare the number of timer-invocations */ while(i++<10){ sleep(1); printf("periodic handler called %lld times\n",rt_count); }// sleep(10); /* instead of the while() loop above */// printf("periodic handler called %lld times\n",rt_count); /* reset the handler befor exiting */ sig.sa_handler = RTLINUX_SIG_IGN; return 0;}void my_handler(int argument){ rt_count++;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -