~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/my_getsystime.cc

Style cleanup around TransactionContext::modified_non_trans_table and dead code removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
   exists some common code that should be merged into a function.
23
23
*/
24
24
 
25
 
#include "mysys_priv.h"
26
 
#include "my_static.h"
 
25
#include "config.h"
 
26
#include "drizzled/my_time.h"
27
27
 
28
28
#if TIME_WITH_SYS_TIME
29
29
# include <sys/time.h>
34
34
# else
35
35
#  include <time.h>
36
36
# endif
37
 
#endif 
 
37
#endif
 
38
 
 
39
namespace drizzled
 
40
{
38
41
 
39
42
uint64_t my_getsystime()
40
43
{
50
53
#endif
51
54
}
52
55
 
53
 
 
54
 
/*
55
 
  Return current time
56
 
 
57
 
  SYNOPSIS
58
 
    my_time()
59
 
    flags       If MY_WME is set, write error if time call fails
60
 
 
61
 
*/
62
 
 
63
 
time_t my_time(myf flags)
64
 
{
65
 
  time_t t;
66
 
#ifdef HAVE_GETHRTIME
67
 
  (void)flags;
68
 
  (void) my_micro_time_and_time(&t);
69
 
  return t;
70
 
#else
71
 
  /* The following loop is here beacuse time() may fail on some systems */
72
 
  while ((t= time(0)) == (time_t) -1)
73
 
  {
74
 
    if (flags & MY_WME)
75
 
      fprintf(stderr, "%s: Warning: time() call failed\n", my_progname);
76
 
  }
77
 
  return t;
78
 
#endif
79
 
}
80
 
 
81
 
 
82
56
/*
83
57
  Return time in micro seconds
84
58
 
143
117
 
144
118
uint64_t my_micro_time_and_time(time_t *time_arg)
145
119
{
146
 
#if defined(HAVE_GETHRTIME)
147
 
  /*
148
 
    Solaris has a very slow time() call. We optimize this by using the very
149
 
    fast gethrtime() call and only calling time() every 1/2 second
150
 
  */
151
 
 
152
 
#define DELTA_FOR_SECONDS 500000000LL  /* Half a second */
153
 
 
154
 
  static hrtime_t prev_gethrtime= 0;
155
 
  static time_t cur_time= 0;
156
 
  hrtime_t cur_gethrtime;
157
 
 
158
 
  pthread_mutex_lock(&THR_LOCK_time);
159
 
  cur_gethrtime= gethrtime();
160
 
  if ((cur_gethrtime - prev_gethrtime) > DELTA_FOR_SECONDS)
161
 
  {
162
 
    cur_time= time(0);
163
 
    prev_gethrtime= cur_gethrtime;
164
 
  }
165
 
  *time_arg= cur_time;
166
 
  pthread_mutex_unlock(&THR_LOCK_time);
167
 
  return cur_gethrtime/1000;
168
 
#else
169
120
  uint64_t newtime;
170
121
  struct timeval t;
171
122
  /*
172
123
    The following loop is here because gettimeofday may fail on some systems
173
124
  */
174
 
  while (gettimeofday(&t, NULL) != 0)
175
 
  {}
 
125
  while (gettimeofday(&t, NULL) != 0) {}
176
126
  *time_arg= t.tv_sec;
177
127
  newtime= (uint64_t)t.tv_sec * 1000000 + t.tv_usec;
 
128
 
178
129
  return newtime;
179
 
#endif  /* defined(HAVE_GETHRTIME) */
180
 
}
181
 
 
182
 
 
183
 
/*
184
 
  Returns current time
185
 
 
186
 
  SYNOPSIS
187
 
    my_time_possible_from_micro()
188
 
    microtime           Value from very recent my_micro_time()
189
 
 
190
 
  NOTES
191
 
    This function returns the current time. The microtime argument is only used
192
 
    if my_micro_time() uses a function that can safely be converted to the
193
 
    current time.
194
 
 
195
 
  RETURN
196
 
    current time
197
 
*/
198
 
 
199
 
time_t my_time_possible_from_micro(uint64_t microtime)
200
 
{
201
 
#if defined(HAVE_GETHRTIME)
202
 
  (void) microtime;
203
 
  return my_time(0);                            /* Cached time */
204
 
#else
205
 
  return (time_t) (microtime / 1000000);
206
 
#endif  /* defined(HAVE_GETHRTIME) */
207
 
}
208
 
 
 
130
}
 
131
 
 
132
} /* namespace drizzled */