source: trunk/packages/xen-3.1/xen-3.1/tools/vnet/vnet-module/timer_util.c @ 34

Last change on this file since 34 was 34, checked in by hartmans, 18 years ago

Add xen and xen-common

File size: 1.8 KB
Line 
1/*
2 * Copyright (C) 2005 Mike Wray <mike.wray@hp.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free software Foundation, Inc.,
16 * 59 Temple Place, suite 330, Boston, MA 02111-1307 USA
17 *
18 */
19
20#ifdef __KERNEL__
21#include <linux/config.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/init.h>
25#include <linux/string.h>
26#include <linux/version.h>
27
28#include <linux/spinlock.h>
29#include <asm/semaphore.h>
30
31#else
32
33#include "sys_kernel.h"
34#include "spinlock.h"
35
36#endif
37
38#include "timer_util.h"
39
40#define MODULE_NAME "TIMER"
41#define DEBUG 1
42#undef DEBUG
43#include "debug.h"
44
45#ifdef __KERNEL__
46
47void timer_init(struct timer_list *timer, void (*fn)(unsigned long), void *data){
48    init_timer(timer);
49    timer->data = (unsigned long)data;
50    timer->function = fn;
51}
52
53void timer_set(struct timer_list *timer, unsigned long ttl){
54    unsigned long now = jiffies;
55    timer->expires = now + ttl;
56    add_timer(timer);
57}
58
59#else
60
61void timer_init(struct Timer *timer, void (*fn)(unsigned long), void *data){
62    *timer = (struct Timer){};
63    timer->data = (unsigned long)data;
64    timer->fn = fn;
65}
66
67void timer_set(struct Timer *timer, unsigned long ttl){
68    double now = time_now();
69    timer->expiry = now + (double)ttl/(double)HZ;
70    Timer_cancel(timer);
71    Timer_add(timer);
72}
73
74#endif
Note: See TracBrowser for help on using the repository browser.