diff options
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | include/my_sys.h | 1 | ||||
-rw-r--r-- | mysys/Makefile.am | 2 | ||||
-rw-r--r-- | mysys/my_getsystime.c | 40 | ||||
-rw-r--r-- | sql/item_strfunc.cc | 10 |
5 files changed, 44 insertions, 11 deletions
diff --git a/configure.in b/configure.in index 6165702a86d..1c22cb7af08 100644 --- a/configure.in +++ b/configure.in @@ -1839,7 +1839,7 @@ AC_CHECK_FUNCS(alarm bcmp bfill bmove bzero chsize cuserid fchmod fcntl \ getcwd gethostbyaddr_r gethostbyname_r getpass getpassphrase getpwnam \ getpwuid getrlimit getrusage getwd gmtime_r index initgroups isnan \ localtime_r locking longjmp lrand48 madvise mallinfo memcpy memmove \ - mkstemp mlockall perror poll pread pthread_attr_create \ + mkstemp mlockall perror poll pread pthread_attr_create clock_gettime \ pthread_attr_getstacksize pthread_attr_setprio pthread_attr_setschedparam \ pthread_attr_setstacksize pthread_condattr_create pthread_getsequence_np \ pthread_key_delete pthread_rwlock_rdlock pthread_setprio \ diff --git a/include/my_sys.h b/include/my_sys.h index 6547022601d..3e34e1a9ac3 100644 --- a/include/my_sys.h +++ b/include/my_sys.h @@ -739,6 +739,7 @@ extern ulong crc32(ulong crc, const uchar *buf, uint len); extern uint my_set_max_open_files(uint files); void my_free_open_file_info(void); +ulonglong my_getsystime(void); my_bool my_gethwaddr(uchar *to); /* character sets */ 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 +} diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 216df5c17d6..fdf65a1f834 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2654,14 +2654,6 @@ static const char hex[] = "0123456789abcdef"; #define UUID_VERSION 0x1000 #define UUID_VARIANT 0x8000 -static ulonglong get_uuid_time() -{ - struct timeval tv; - gettimeofday(&tv,NULL); - return (ulonglong)tv.tv_sec*10000000 + - (ulonglong)tv.tv_usec*10 + UUID_TIME_OFFSET + nanoseq; -} - static void tohex(char *to, uint from, uint len) { to+= len; @@ -2710,7 +2702,7 @@ String *Item_func_uuid::val_str(String *str) set_clock_seq_str(); } - ulonglong tv=get_uuid_time(); + ulonglong tv=my_getsystime() + UUID_TIME_OFFSET + nanoseq; if (unlikely(tv < uuid_time)) set_clock_seq_str(); else |