Ivo van Poorten
/
opus-una
A Small Cooperative Multitasking Kernel
Embed:
(wiki syntax)
Show/hide line numbers
timer-unix-c.h
00001 /* Opus Una - A Small Cooperative Multitasking Kernel in C 00002 * 00003 * Copyright (C) 2011 by Ivo van Poorten <ivop@euronet.nl> 00004 * This file is licensed under the terms of the GNU Lesser 00005 * General Public License, version 3. 00006 */ 00007 00008 /* Run the kernel as a process on Unix */ 00009 00010 #include "timer.h" 00011 #include "kernel.h" 00012 00013 #include <sys/time.h> 00014 #include <signal.h> 00015 #include <string.h> 00016 #include <unistd.h> 00017 00018 static void timer_sr(int x) { 00019 ou_ticks++; 00020 ou_update_tasks(); 00021 } 00022 00023 void ou_start_timer(void) { 00024 struct itimerval val; 00025 struct sigaction act; 00026 00027 memset(&act, 0, sizeof(act)); 00028 00029 act.sa_handler = timer_sr; 00030 sigaction(SIGALRM, &act, NULL); // signal() is not portable 00031 00032 val.it_interval.tv_usec = 10000; // 10ms 00033 val.it_interval.tv_sec = 0; 00034 val.it_value.tv_usec = 10000; // 10ms 00035 val.it_value.tv_sec = 0; 00036 setitimer(ITIMER_REAL, &val, NULL); 00037 } 00038 00039 void ou_idle(void) { 00040 usleep(5); // save power/cpu time/et cetera... 00041 }
Generated on Wed Jul 13 2022 20:40:52 by 1.7.2