~ubuntu-branches/ubuntu/jaunty/9base/jaunty

« back to all changes in this revision

Viewing changes to lib9/sleep.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2006-01-25 15:33:00 UTC
  • Revision ID: james.westby@ubuntu.com-20060125153300-6hh4p9wx8iqqply5
Tags: upstream-2
ImportĀ upstreamĀ versionĀ 2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <u.h>
 
2
#define NOPLAN9DEFINES
 
3
#include <sys/time.h>
 
4
#include <sched.h>
 
5
#include <libc.h>
 
6
 
 
7
int
 
8
p9sleep(long milli)
 
9
{
 
10
        struct timeval tv;
 
11
 
 
12
        if(milli == 0){
 
13
                sched_yield();
 
14
                return 0;
 
15
        }
 
16
 
 
17
        tv.tv_sec = milli/1000;
 
18
        tv.tv_usec = (milli%1000)*1000;
 
19
        return select(0, 0, 0, 0, &tv);
 
20
}
 
21
 
 
22
long
 
23
p9alarm(ulong milli)
 
24
{
 
25
        struct itimerval itv;
 
26
        struct itimerval oitv;
 
27
 
 
28
        itv.it_interval.tv_sec = 0;
 
29
        itv.it_interval.tv_usec = 0;
 
30
        itv.it_value.tv_sec = milli/1000;
 
31
        itv.it_value.tv_usec = (milli%1000)*1000;
 
32
        if(setitimer(ITIMER_REAL, &itv, &oitv) < 0)
 
33
                return -1;
 
34
        return oitv.it_value.tv_sec*1000+oitv.it_value.tv_usec/1000;
 
35
}