summaryrefslogtreecommitdiff
path: root/mysys/my_getsystime.c
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2004-03-02 22:21:12 +0100
committerunknown <serg@serg.mylan>2004-03-02 22:21:12 +0100
commitbbb3d27a5d8528eec7100210457a254b72818743 (patch)
tree04021c7bb53d438f34c122e5717a463568477d11 /mysys/my_getsystime.c
parent48b6cc2b2e5e336efec65d8daf1c3e649a77adb5 (diff)
downloadmariadb-git-bbb3d27a5d8528eec7100210457a254b72818743.tar.gz
my_getsystime()
Diffstat (limited to 'mysys/my_getsystime.c')
-rw-r--r--mysys/my_getsystime.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/mysys/my_getsystime.c b/mysys/my_getsystime.c
new file mode 100644
index 00000000000..33c2163120f
--- /dev/null
+++ b/mysys/my_getsystime.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+/* get time since epoc in 100 nanosec units */
+/* thus to get the current time we should use the system function
+ with the highest possible resolution */
+
+#include "mysys_priv.h"
+ulonglong my_getsystime()
+{
+#ifdef HAVE_CLOCK_GETTIME
+ struct timespec tp;
+ clock_gettime(CLOCK_REALTIME, &tp);
+ return (ulonglong)tp.tv_sec*10000000+(ulonglong)tp.tv_nsec/100;
+#elif defined(__WIN__)
+ /* TODO: use GetSystemTimeAsFileTime here or
+ QueryPerformanceCounter/QueryPerformanceFrequency */
+ struct _timeb tb;
+ _ftime(&tb);
+ return (ulonglong)tb.time*10000000+(ulonglong)tb.millitm*10000;
+#else
+ /* TODO: check for other possibilities for hi-res timestamping */
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return (ulonglong)tv.tv_sec*10000000+(ulonglong)tv.tv_usec*10;
+#endif
+}