Subversion Repositories shark

Rev

Rev 330 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
42 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
/*      Inline functions for managing timespec structures.
23
        All timespec values are pointers!!!
24
        This file defines these functions:
25
                TIMESPEC2NANOSEC(t)
26
                converts a timespec value to a nanosec value, and return
27
                        it, no checks
28
                TIMESPEC2USEC(t)
29
                converts a timespec value to a nanosec value, and return
30
                it, no checks
31
                NULL_TIMESPEC(t)
32
                the timespec value is set to the Epoch (=0)
33
                ADDNANO2TIMESPEC(n, t)
34
                t = t + n
35
                ADDUSEC2TIMESPEC(m, t)
36
                t = t + m
131 giacomo 37
                SUBTIMESPEC(s1, s2, d) Works well only if s1 >= s2
42 pj 38
                d = s1 - s2
39
                ADDTIMESPEC(s1, s2, d)
40
                d = s1 + s2
41
                TIMESPEC_A_LT_B(a,b)
42
                a < b
43
                TIMESPEC_A_GT_B(a,b)
44
                a > b
45
                TIMESPEC_A_EQ_B(a,b)
46
                a == b
47
                TIMESPEC_A_NEQ_B(a,b)
48
                a != b
49
                TIMESPEC_ASSIGN(t1,t2)
50
                t1 = t2 */
51
 
52
#ifndef __LL_SYS_LL_TIME_H__
53
#define __LL_SYS_LL_TIME_H__
54
 
55
#include <ll/i386/defs.h>
56
BEGIN_DEF
57
 
500 giacomo 58
#define _STRUCT_TIMESPEC
59
 
42 pj 60
struct timespec {
131 giacomo 61
        long    tv_sec;         /* Seconds */
62
        long    tv_nsec;        /* Nanoseconds */
42 pj 63
};
64
 
65
/*
66
 * these macros come from the Utah Flux oskit...
67
 */
68
 
69
#define TIMESPEC2NANOSEC(t)     ((t)->tv_sec * 1000000000 + (t)->tv_nsec)
70
#define TIMESPEC2USEC(t)     ((t)->tv_sec * 1000000 + (t)->tv_nsec / 1000)
131 giacomo 71
#define NULL_TIMESPEC(t)        ((t)->tv_sec = (t)->tv_nsec = 0)
72
#define ADDNANO2TIMESPEC(n, t)  ((t)->tv_nsec += (n), \
73
                (t)->tv_sec += (t)->tv_nsec / 1000000000, \
74
                (t)->tv_nsec %= 1000000000)
42 pj 75
 
131 giacomo 76
#define SUBTIMESPEC(s1, s2, d)                               \
77
        ((d)->tv_nsec = ((s1)->tv_nsec >= (s2)->tv_nsec) ?   \
78
         (((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec),       \
79
          (s1)->tv_nsec - (s2)->tv_nsec)                     \
80
         :                                                   \
81
         (((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec - 1),   \
82
          (1000000000 + (s1)->tv_nsec - (s2)->tv_nsec)))
42 pj 83
 
131 giacomo 84
/*
85
 * ...and these not!
86
 */
42 pj 87
 
88
extern __inline__ void ADDTIMESPEC(const struct timespec *s1,
89
                                   const struct timespec *s2,
90
                                   struct timespec *d)
91
{
131 giacomo 92
  d->tv_sec  = s1->tv_sec + s2->tv_sec;
93
  d->tv_nsec = s1->tv_nsec + s2->tv_nsec;
42 pj 94
 
131 giacomo 95
  if (d->tv_nsec < 0) {
96
    d->tv_sec--;
97
    d->tv_nsec += 1000000000;
98
  } else if (d->tv_nsec >= 1000000000) {
99
    d->tv_sec++;
100
    d->tv_nsec -= 1000000000;
101
  }
102
}
42 pj 103
 
104
 
131 giacomo 105
#define ADDUSEC2TIMESPEC(m, t)  ((t)->tv_nsec += (m%1000000)*1000,        \
106
                (t)->tv_sec += ((t)->tv_nsec / 1000000000) + (m/1000000), \
107
                (t)->tv_nsec %= 1000000000)
42 pj 108
 
109
#define TIMESPEC_A_LT_B(a,b)                                            \
110
        (                                                               \
111
        ((a)->tv_sec <  (b)->tv_sec) ||                                 \
131 giacomo 112
        ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec < (b)->tv_nsec)    \
42 pj 113
        )
114
 
115
#define TIMESPEC_A_GT_B(a,b)                                            \
116
        (                                                               \
117
        ((a)->tv_sec >  (b)->tv_sec) ||                                 \
131 giacomo 118
        ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec > (b)->tv_nsec)    \
42 pj 119
        )
120
 
121
#define TIMESPEC_A_EQ_B(a,b)                                            \
122
        ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec == (b)->tv_nsec)
123
 
131 giacomo 124
#define TIMESPEC_A_NEQ_B(a,b)                                            \
42 pj 125
        ((a)->tv_sec != (b)->tv_sec || (a)->tv_nsec != (b)->tv_nsec)
126
 
127
#define TIMESPEC_ASSIGN(t1,t2) \
131 giacomo 128
        ((t1)->tv_sec = (t2)->tv_sec, (t1)->tv_nsec = (t2)->tv_nsec)
42 pj 129
 
130
#if 0
131
#define PITSPEC2TIMESPEC(a,b) \
305 giacomo 132
     ((b)->tv_nsec = (((DWORD)((a)->units) * 1000) / 1197) * 1000, \
133
        (b)->tv_sec = ((a)->gigas * 1197) / 1000) /*, \
134
        (b)->tv_sec += (b)->tv_nsec / 1000000000, \
42 pj 135
        (b)->tv_nsec %= 1000000000)     */
136
#else
137
/*#define PITSPEC2TIMESPEC(a,b) \
305 giacomo 138
     ((b)->tv_nsec = (((DWORD)((a)->units) * 1000) / 1197) * 1000, \
139
        (b)->tv_nsec += (((a)->gigas * 1197) % 1000) * 1000000, \
140
        (b)->tv_sec = ((a)->gigas * 1197) / 1000 , \
42 pj 141
        (b)->tv_sec += (b)->tv_nsec / 1000000000, \
142
        (b)->tv_nsec %= 1000000000)*/
143
#define PITSPEC2TIMESPEC(a,b) \
330 giacomo 144
     ((b)->tv_nsec = (((DWORD)((a)->units) * 1000) / 1193), \
145
        (b)->tv_nsec += (((a)->gigas * 1193) % 1000) * 1000, \
146
        (b)->tv_sec = ((a)->gigas * 1193) / 1000 , \
42 pj 147
        (b)->tv_sec += (b)->tv_nsec / 1000000, \
148
        (b)->tv_nsec %= 1000000, \
149
        (b)->tv_nsec *= 1000)
150
#endif
151
 
152
TIME ll_gettime(int mode, struct timespec *tsres);
153
 
154
#define TIME_PTICK      1
155
#define TIME_EXACT      2
156
#define TIME_NEW        3
157
 
158
END_DEF
159
#endif