Subversion Repositories shark

Rev

Rev 1683 | 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
 
536 giacomo 58
#ifndef _STRUCT_TIMESPEC
500 giacomo 59
#define _STRUCT_TIMESPEC
60
 
42 pj 61
struct timespec {
131 giacomo 62
        long    tv_sec;         /* Seconds */
63
        long    tv_nsec;        /* Nanoseconds */
42 pj 64
};
65
 
536 giacomo 66
#endif
67
 
42 pj 68
/*
69
 * these macros come from the Utah Flux oskit...
70
 */
71
 
72
#define TIMESPEC2NANOSEC(t)     ((t)->tv_sec * 1000000000 + (t)->tv_nsec)
73
#define TIMESPEC2USEC(t)     ((t)->tv_sec * 1000000 + (t)->tv_nsec / 1000)
131 giacomo 74
#define NULL_TIMESPEC(t)        ((t)->tv_sec = (t)->tv_nsec = 0)
75
#define ADDNANO2TIMESPEC(n, t)  ((t)->tv_nsec += (n), \
76
                (t)->tv_sec += (t)->tv_nsec / 1000000000, \
77
                (t)->tv_nsec %= 1000000000)
42 pj 78
 
131 giacomo 79
#define SUBTIMESPEC(s1, s2, d)                               \
80
        ((d)->tv_nsec = ((s1)->tv_nsec >= (s2)->tv_nsec) ?   \
81
         (((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec),       \
82
          (s1)->tv_nsec - (s2)->tv_nsec)                     \
83
         :                                                   \
84
         (((d)->tv_sec = (s1)->tv_sec - (s2)->tv_sec - 1),   \
85
          (1000000000 + (s1)->tv_nsec - (s2)->tv_nsec)))
42 pj 86
 
131 giacomo 87
/*
88
 * ...and these not!
89
 */
42 pj 90
 
91
extern __inline__ void ADDTIMESPEC(const struct timespec *s1,
92
                                   const struct timespec *s2,
93
                                   struct timespec *d)
94
{
131 giacomo 95
  d->tv_sec  = s1->tv_sec + s2->tv_sec;
96
  d->tv_nsec = s1->tv_nsec + s2->tv_nsec;
42 pj 97
 
131 giacomo 98
  if (d->tv_nsec < 0) {
99
    d->tv_sec--;
100
    d->tv_nsec += 1000000000;
101
  } else if (d->tv_nsec >= 1000000000) {
102
    d->tv_sec++;
103
    d->tv_nsec -= 1000000000;
104
  }
105
}
42 pj 106
 
107
 
131 giacomo 108
#define ADDUSEC2TIMESPEC(m, t)  ((t)->tv_nsec += (m%1000000)*1000,        \
109
                (t)->tv_sec += ((t)->tv_nsec / 1000000000) + (m/1000000), \
110
                (t)->tv_nsec %= 1000000000)
42 pj 111
 
112
#define TIMESPEC_A_LT_B(a,b)                                            \
113
        (                                                               \
114
        ((a)->tv_sec <  (b)->tv_sec) ||                                 \
131 giacomo 115
        ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec < (b)->tv_nsec)    \
42 pj 116
        )
117
 
118
#define TIMESPEC_A_GT_B(a,b)                                            \
119
        (                                                               \
120
        ((a)->tv_sec >  (b)->tv_sec) ||                                 \
131 giacomo 121
        ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec > (b)->tv_nsec)    \
42 pj 122
        )
123
 
124
#define TIMESPEC_A_EQ_B(a,b)                                            \
125
        ((a)->tv_sec == (b)->tv_sec && (a)->tv_nsec == (b)->tv_nsec)
126
 
131 giacomo 127
#define TIMESPEC_A_NEQ_B(a,b)                                            \
42 pj 128
        ((a)->tv_sec != (b)->tv_sec || (a)->tv_nsec != (b)->tv_nsec)
129
 
130
#define TIMESPEC_ASSIGN(t1,t2) \
131 giacomo 131
        ((t1)->tv_sec = (t2)->tv_sec, (t1)->tv_nsec = (t2)->tv_nsec)
42 pj 132
 
133
#if 0
134
#define PITSPEC2TIMESPEC(a,b) \
305 giacomo 135
     ((b)->tv_nsec = (((DWORD)((a)->units) * 1000) / 1197) * 1000, \
136
        (b)->tv_sec = ((a)->gigas * 1197) / 1000) /*, \
137
        (b)->tv_sec += (b)->tv_nsec / 1000000000, \
42 pj 138
        (b)->tv_nsec %= 1000000000)     */
139
#else
140
/*#define PITSPEC2TIMESPEC(a,b) \
305 giacomo 141
     ((b)->tv_nsec = (((DWORD)((a)->units) * 1000) / 1197) * 1000, \
142
        (b)->tv_nsec += (((a)->gigas * 1197) % 1000) * 1000000, \
143
        (b)->tv_sec = ((a)->gigas * 1197) / 1000 , \
42 pj 144
        (b)->tv_sec += (b)->tv_nsec / 1000000000, \
145
        (b)->tv_nsec %= 1000000000)*/
146
#define PITSPEC2TIMESPEC(a,b) \
330 giacomo 147
     ((b)->tv_nsec = (((DWORD)((a)->units) * 1000) / 1193), \
148
        (b)->tv_nsec += (((a)->gigas * 1193) % 1000) * 1000, \
149
        (b)->tv_sec = ((a)->gigas * 1193) / 1000 , \
42 pj 150
        (b)->tv_sec += (b)->tv_nsec / 1000000, \
151
        (b)->tv_nsec %= 1000000, \
152
        (b)->tv_nsec *= 1000)
153
#endif
154
 
155
TIME ll_gettime(int mode, struct timespec *tsres);
156
 
157
#define TIME_PTICK      1
158
#define TIME_EXACT      2
159
#define TIME_NEW        3
160
 
161
END_DEF
162
#endif