Subversion Repositories HelenOS-historic

Rev

Rev 1435 | Rev 1441 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1435 Rev 1439
Line 36... Line 36...
36
#include <as.h>
36
#include <as.h>
37
#include <ddi.h>
37
#include <ddi.h>
38
 
38
 
39
/* Pointers to public variables with time */
39
/* Pointers to public variables with time */
40
struct {
40
struct {
41
    volatile sysarg_t seconds;
41
    volatile sysarg_t seconds1;
42
    volatile sysarg_t useconds;
42
    volatile sysarg_t useconds;
43
    volatile sysarg_t useconds2;
43
    volatile sysarg_t seconds2;
44
} *ktime = NULL;
44
} *ktime = NULL;
45
 
45
 
46
 
46
 
47
/** POSIX gettimeofday
47
/** POSIX gettimeofday
48
 *
48
 *
Line 55... Line 55...
55
 */
55
 */
56
#define TMAREA (100*1024*1024)
56
#define TMAREA (100*1024*1024)
57
int gettimeofday(struct timeval *tv, struct timezone *tz)
57
int gettimeofday(struct timeval *tv, struct timezone *tz)
58
{
58
{
59
    void *mapping;
59
    void *mapping;
60
    sysarg_t seconds,useconds;
60
    sysarg_t s1, s2;
61
    sysarg_t t1;
61
    sysarg_t t1;
62
    int res;
62
    int res;
63
 
63
 
64
    if (!ktime) {
64
    if (!ktime) {
65
        /* TODO: specify better, where to map the area */
65
        /* TODO: specify better, where to map the area */
Line 76... Line 76...
76
        ktime = (void *) (TMAREA);
76
        ktime = (void *) (TMAREA);
77
    }
77
    }
78
    tz->tz_minuteswest = 0;
78
    tz->tz_minuteswest = 0;
79
    tz->tz_dsttime = DST_NONE;
79
    tz->tz_dsttime = DST_NONE;
80
retry:
80
retry:
81
    seconds = ktime->seconds;
81
    s1 = ktime->seconds1;
82
    read_barrier();
-
 
83
    tv->tv_usec = ktime->useconds;
82
    tv->tv_usec = ktime->useconds;
84
    read_barrier();
83
    read_barrier();
85
    tv->tv_sec = ktime->seconds;
84
    s2 = ktime->seconds2;
86
    if (tv->tv_usec == 0 && seconds == tv->tv_sec &&
-
 
87
        ktime->useconds2 != 0) {
85
    if (s1 != s2) {
88
        read_barrier();
86
        tv->tv_usec = 0;
89
        goto retry;
87
        tv->tv_sec = s1 > s2 ? s1 : s2;
90
    }
88
    } else
91
 
-
 
92
    if (seconds != tv->tv_sec)
-
 
93
        tv->tv_usec = ktime->useconds;
89
        tv->tv_sec = s1;
94
 
90
 
95
    return 0;
91
    return 0;
96
}
92
}