diff options
author | serg@serg.mylan <> | 2004-03-02 22:21:12 +0100 |
---|---|---|
committer | serg@serg.mylan <> | 2004-03-02 22:21:12 +0100 |
commit | a05c54b6c2c37bdcddfae537b7ff3314051c2a86 (patch) | |
tree | 04021c7bb53d438f34c122e5717a463568477d11 /mysys | |
parent | f90555e0d5717e6b9e0a5893e0c375aa3b6aa7f5 (diff) | |
download | mariadb-git-a05c54b6c2c37bdcddfae537b7ff3314051c2a86.tar.gz |
my_getsystime()
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/Makefile.am | 2 | ||||
-rw-r--r-- | mysys/my_getsystime.c | 40 |
2 files changed, 41 insertions, 1 deletions
diff --git a/mysys/Makefile.am b/mysys/Makefile.am index 77b17d28ba3..d4290bbc49b 100644 --- a/mysys/Makefile.am +++ b/mysys/Makefile.am @@ -34,7 +34,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c \ mf_tempdir.c my_lock.c mf_brkhant.c my_alarm.c \ my_malloc.c my_realloc.c my_once.c mulalloc.c \ my_alloc.c safemalloc.c my_new.cc \ - my_fopen.c my_fstream.c \ + my_fopen.c my_fstream.c my_getsystime.c \ my_error.c errors.c my_div.c my_messnc.c \ mf_format.c mf_same.c mf_dirname.c mf_fn_ext.c \ my_symlink.c my_symlink2.c \ 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 +} |