~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/include/linux/time.h

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef _LINUX_TIME_H
  2 #define _LINUX_TIME_H
  3 
  4 #include <asm/param.h>
  5 #include <linux/types.h>
  6 
  7 #ifndef _STRUCT_TIMESPEC
  8 #define _STRUCT_TIMESPEC
  9 struct timespec {
 10         time_t  tv_sec;         /* seconds */
 11         long    tv_nsec;        /* nanoseconds */
 12 };
 13 #endif /* _STRUCT_TIMESPEC */
 14 
 15 #ifdef __KERNEL__
 16 
 17 /*
 18  * Change timeval to jiffies, trying to avoid the
 19  * most obvious overflows..
 20  *
 21  * And some not so obvious.
 22  *
 23  * Note that we don't want to return MAX_LONG, because
 24  * for various timeout reasons we often end up having
 25  * to wait "jiffies+1" in order to guarantee that we wait
 26  * at _least_ "jiffies" - so "jiffies+1" had better still
 27  * be positive.
 28  */
 29 #define MAX_JIFFY_OFFSET ((~0UL >> 1)-1)
 30 
 31 static __inline__ unsigned long
 32 timespec_to_jiffies(struct timespec *value)
 33 {
 34         unsigned long sec = value->tv_sec;
 35         long nsec = value->tv_nsec;
 36 
 37         if (sec >= (MAX_JIFFY_OFFSET / HZ))
 38                 return MAX_JIFFY_OFFSET;
 39         nsec += 1000000000L / HZ - 1;
 40         nsec /= 1000000000L / HZ;
 41         return HZ * sec + nsec;
 42 }
 43 
 44 static __inline__ void
 45 jiffies_to_timespec(unsigned long jiffies, struct timespec *value)
 46 {
 47         value->tv_nsec = (jiffies % HZ) * (1000000000L / HZ);
 48         value->tv_sec = jiffies / HZ;
 49 }
 50 
 51 
 52 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
 53  * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
 54  * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
 55  *
 56  * [For the Julian calendar (which was used in Russia before 1917,
 57  * Britain & colonies before 1752, anywhere else before 1582,
 58  * and is still in use by some communities) leave out the
 59  * -year/100+year/400 terms, and add 10.]
 60  *
 61  * This algorithm was first published by Gauss (I think).
 62  *
 63  * WARNING: this function will overflow on 2106-02-07 06:28:16 on
 64  * machines were long is 32-bit! (However, as time_t is signed, we
 65  * will already get problems at other places on 2038-01-19 03:14:08)
 66  */
 67 static inline unsigned long
 68 mktime (unsigned int year, unsigned int mon,
 69         unsigned int day, unsigned int hour,
 70         unsigned int min, unsigned int sec)
 71 {
 72         if (0 >= (int) (mon -= 2)) {    /* 1..12 -> 11,12,1..10 */
 73                 mon += 12;              /* Puts Feb last since it has leap day */
 74                 year -= 1;
 75         }
 76 
 77         return (((
 78                 (unsigned long) (year/4 - year/100 + year/400 + 367*mon/12 + day) +
 79                         year*365 - 719499
 80             )*24 + hour /* now have hours */
 81           )*60 + min /* now have minutes */
 82         )*60 + sec; /* finally seconds */
 83 }
 84 
 85 #endif /* __KERNEL__ */
 86 
 87 
 88 struct timeval {
 89         time_t          tv_sec;         /* seconds */
 90         suseconds_t     tv_usec;        /* microseconds */
 91 };
 92 
 93 struct timezone {
 94         int     tz_minuteswest; /* minutes west of Greenwich */
 95         int     tz_dsttime;     /* type of dst correction */
 96 };
 97 
 98 #define NFDBITS                 __NFDBITS
 99 
100 #ifdef __KERNEL__
101 extern void do_gettimeofday(struct timeval *tv);
102 extern void do_settimeofday(struct timeval *tv);
103 extern void get_fast_time(struct timeval *tv);
104 extern void (*do_get_fast_time)(struct timeval *);
105 #endif
106 
107 #define FD_SETSIZE              __FD_SETSIZE
108 #define FD_SET(fd,fdsetp)       __FD_SET(fd,fdsetp)
109 #define FD_CLR(fd,fdsetp)       __FD_CLR(fd,fdsetp)
110 #define FD_ISSET(fd,fdsetp)     __FD_ISSET(fd,fdsetp)
111 #define FD_ZERO(fdsetp)         __FD_ZERO(fdsetp)
112 
113 /*
114  * Names of the interval timers, and structure
115  * defining a timer setting.
116  */
117 #define ITIMER_REAL     0
118 #define ITIMER_VIRTUAL  1
119 #define ITIMER_PROF     2
120 
121 struct  itimerspec {
122         struct  timespec it_interval;    /* timer period */
123         struct  timespec it_value;       /* timer expiration */
124 };
125 
126 struct  itimerval {
127         struct  timeval it_interval;    /* timer interval */
128         struct  timeval it_value;       /* current value */
129 };
130 
131 #endif
132 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.