~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysys/my_getsystime.c

  • Committer: Monty Taylor
  • Date: 2008-07-05 18:10:38 UTC
  • mto: This revision was merged to the branch mainline in revision 63.
  • Revision ID: monty@inaugust.com-20080705181038-0ih0nnamu5qrut0y
Fixed prototypes. Cleaned define a little bit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "mysys_priv.h"
26
26
#include "my_static.h"
27
27
 
28
 
#if TIME_WITH_SYS_TIME
29
 
# include <sys/time.h>
30
 
# include <time.h>
31
 
#else
32
 
# if HAVE_SYS_TIME_H
33
 
#  include <sys/time.h>
34
 
# else
35
 
#  include <time.h>
36
 
# endif
37
 
#endif 
38
 
 
39
 
uint64_t my_getsystime()
 
28
ulonglong my_getsystime()
40
29
{
41
30
#ifdef HAVE_CLOCK_GETTIME
42
31
  struct timespec tp;
43
32
  clock_gettime(CLOCK_REALTIME, &tp);
44
 
  return (uint64_t)tp.tv_sec*10000000+(uint64_t)tp.tv_nsec/100;
 
33
  return (ulonglong)tp.tv_sec*10000000+(ulonglong)tp.tv_nsec/100;
45
34
#else
46
35
  /* TODO: check for other possibilities for hi-res timestamping */
47
36
  struct timeval tv;
48
37
  gettimeofday(&tv,NULL);
49
 
  return (uint64_t)tv.tv_sec*10000000+(uint64_t)tv.tv_usec*10;
 
38
  return (ulonglong)tv.tv_sec*10000000+(ulonglong)tv.tv_usec*10;
50
39
#endif
51
40
}
52
41
 
99
88
    Value in microseconds from some undefined point in time
100
89
*/
101
90
 
102
 
uint64_t my_micro_time()
 
91
ulonglong my_micro_time()
103
92
{
104
93
#if defined(HAVE_GETHRTIME)
105
94
  return gethrtime()/1000;
106
95
#else
107
 
  uint64_t newtime;
 
96
  ulonglong newtime;
108
97
  struct timeval t;
109
98
  /*
110
99
    The following loop is here because gettimeofday may fail on some systems
111
100
  */
112
101
  while (gettimeofday(&t, NULL) != 0)
113
102
  {}
114
 
  newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
 
103
  newtime= (ulonglong)t.tv_sec * 1000000 + t.tv_usec;
115
104
  return newtime;
116
105
#endif  /* defined(HAVE_GETHRTIME) */
117
106
}
139
128
    Value in microseconds from some undefined point in time
140
129
*/
141
130
 
 
131
#define DELTA_FOR_SECONDS LL(500000000)  /* Half a second */
142
132
 
143
 
uint64_t my_micro_time_and_time(time_t *time_arg)
 
133
ulonglong my_micro_time_and_time(time_t *time_arg)
144
134
{
145
135
#if defined(HAVE_GETHRTIME)
146
136
  /*
147
137
    Solaris has a very slow time() call. We optimize this by using the very
148
138
    fast gethrtime() call and only calling time() every 1/2 second
149
139
  */
150
 
 
151
 
#define DELTA_FOR_SECONDS 500000000LL  /* Half a second */
152
 
 
153
140
  static hrtime_t prev_gethrtime= 0;
154
141
  static time_t cur_time= 0;
155
142
  hrtime_t cur_gethrtime;
165
152
  pthread_mutex_unlock(&THR_LOCK_time);
166
153
  return cur_gethrtime/1000;
167
154
#else
168
 
  uint64_t newtime;
 
155
  ulonglong newtime;
169
156
  struct timeval t;
170
157
  /*
171
158
    The following loop is here because gettimeofday may fail on some systems
173
160
  while (gettimeofday(&t, NULL) != 0)
174
161
  {}
175
162
  *time_arg= t.tv_sec;
176
 
  newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
 
163
  newtime= (ulonglong)t.tv_sec * 1000000 + t.tv_usec;
177
164
  return newtime;
178
165
#endif  /* defined(HAVE_GETHRTIME) */
179
166
}
195
182
    current time
196
183
*/
197
184
 
198
 
time_t my_time_possible_from_micro(uint64_t microtime __attribute__((unused)))
 
185
time_t my_time_possible_from_micro(ulonglong microtime __attribute__((unused)))
199
186
{
200
187
#if defined(HAVE_GETHRTIME)
201
188
  return my_time(0);                            /* Cached time */