diff options
author | Vladislav Vaintroub <wlad@montyprogram.com> | 2011-05-28 16:57:58 +0200 |
---|---|---|
committer | Vladislav Vaintroub <wlad@montyprogram.com> | 2011-05-28 16:57:58 +0200 |
commit | b519f2b626ebd1f3243a21dc883cefa6a26460f9 (patch) | |
tree | faad721ece99fc071000e695861e37d45acda0e5 | |
parent | 152dfe58678af35769ca3cd66db592d129b4c08b (diff) | |
download | mariadb-git-b519f2b626ebd1f3243a21dc883cefa6a26460f9.tar.gz |
Fix compile errors and warnings and test errors introduced by microseconds push.
Also, change windows timespec definition to be Unix-ish - simplifies handling a lot.
-rw-r--r-- | client/sql_string.cc | 4 | ||||
-rw-r--r-- | include/my_pthread.h | 30 | ||||
-rw-r--r-- | mysql-test/include/type_hrtime.inc | 1 | ||||
-rw-r--r-- | mysys/my_wincond.c | 37 | ||||
-rw-r--r-- | sql/field.cc | 4 | ||||
-rw-r--r-- | sql/item_timefunc.cc | 2 | ||||
-rw-r--r-- | sql/set_var.cc | 2 | ||||
-rw-r--r-- | sql/sql_string.cc | 4 | ||||
-rw-r--r-- | storage/maria/tablockman.c | 2 | ||||
-rw-r--r-- | storage/pbxt/src/filesys_xt.cc | 3 | ||||
-rwxr-xr-x | storage/pbxt/src/pthread_xt.cc | 43 | ||||
-rw-r--r-- | storage/pbxt/src/thread_xt.cc | 16 |
12 files changed, 32 insertions, 116 deletions
diff --git a/client/sql_string.cc b/client/sql_string.cc index aa5d64a01d8..315c8d786db 100644 --- a/client/sql_string.cc +++ b/client/sql_string.cc @@ -542,8 +542,8 @@ uint32 String::numchars() int String::charpos(longlong i,uint32 offset) { if (i <= 0) - return i; - return str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,i); + return (int)i; + return (int)str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,(size_t)i); } int String::strstr(const String &s,uint32 offset) diff --git a/include/my_pthread.h b/include/my_pthread.h index e280146c34f..139e5d08437 100644 --- a/include/my_pthread.h +++ b/include/my_pthread.h @@ -75,37 +75,11 @@ typedef volatile LONG my_pthread_once_t; #define MY_PTHREAD_ONCE_INPROGRESS 1 #define MY_PTHREAD_ONCE_DONE 2 -/* - Struct and macros to be used in combination with the - windows implementation of pthread_cond_timedwait -*/ - -/* - Declare a union to make sure FILETIME is properly aligned - so it can be used directly as a 64 bit value. The value - stored is in 100ns units. - */ -union ft64 { - FILETIME ft; - __int64 i64; -}; - struct timespec { - union ft64 tv; - /* The max timeout value in millisecond for pthread_cond_timedwait */ - long max_timeout_msec; + time_t tv_sec; + long tv_nsec; }; -#define set_timespec_time_nsec(ABSTIME,TIME,NSEC) do { \ - (ABSTIME).tv.i64= (TIME)+(__int64)(NSEC)/100; \ - (ABSTIME).max_timeout_msec= (long)((NSEC)/1000000); \ -} while(0) - -#define set_timespec_nsec(ABSTIME,NSEC) do { \ - union ft64 tv; \ - GetSystemTimeAsFileTime(&tv.ft); \ - set_timespec_time_nsec((ABSTIME), tv.i64, (NSEC)); \ -} while(0) void win_pthread_init(void); int win_pthread_setspecific(void *A,void *B,uint length); diff --git a/mysql-test/include/type_hrtime.inc b/mysql-test/include/type_hrtime.inc index f9369d51658..7bde8c609e4 100644 --- a/mysql-test/include/type_hrtime.inc +++ b/mysql-test/include/type_hrtime.inc @@ -15,6 +15,7 @@ insert t1 values (20101211010203.45678); insert t1 values (20101211030405.789e0); insert t1 values (99991231235959e1); select * from t1; +--replace_regex /121000/121094/ /457000/457031/ /789000/789062/ select truncate(a, 6) from t1; # Field::val_real() select a DIV 1 from t1; # Field::val_int() select group_concat(distinct a) from t1; # Field::cmp() diff --git a/mysys/my_wincond.c b/mysys/my_wincond.c index b869b22bdea..e181b24cdef 100644 --- a/mysys/my_wincond.c +++ b/mysys/my_wincond.c @@ -77,31 +77,22 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *abstime) { int result; - long timeout; - union ft64 now; - + DWORD timeout; + long long timeout_us; + my_hrtime_t now; + my_hrtime_t then; if( abstime != NULL ) { - GetSystemTimeAsFileTime(&now.ft); - - /* - Calculate time left to abstime - - subtract start time from current time(values are in 100ns units) - - convert to millisec by dividing with 10000 - */ - timeout= (long)((abstime->tv.i64 - now.i64) / 10000); - - /* Don't allow the timeout to be negative */ - if (timeout < 0) - timeout= 0L; - - /* - Make sure the calucated timeout does not exceed original timeout - value which could cause "wait for ever" if system time changes - */ - if (timeout > abstime->max_timeout_msec) - timeout= abstime->max_timeout_msec; - + now= my_hrtime(); + then.val= 1000000ULL*abstime->tv_sec + abstime->tv_nsec/1000; + timeout_us= then.val - now.val; + + if (timeout_us < 0) + timeout= 0; + else if (timeout_us > 1000ULL*INFINITE) + timeout= INFINITE; + else + timeout= (DWORD)(timeout_us/1000); } else { diff --git a/sql/field.cc b/sql/field.cc index 7976c8b0e3c..1887a87f044 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -4602,7 +4602,7 @@ int Field_timestamp::store(double nr) /* We don't want to store invalid or fuzzy datetime values in TIMESTAMP */ if (nr < 0 || nr > LONGLONG_MAX) - nr= LONGLONG_MAX; + nr= (double)LONGLONG_MAX; tmp= number_to_datetime((longlong) floor(nr), &l_time, (thd->variables.sql_mode & MODE_NO_ZERO_DATE) | @@ -5075,7 +5075,7 @@ int Field_temporal::store(double nr) Lazy_string_double str(nr); if (nr < 0 || nr > LONGLONG_MAX) - nr= LONGLONG_MAX; + nr= (double)LONGLONG_MAX; longlong tmp= number_to_datetime((longlong) floor(nr), <ime, (TIME_FUZZY_DATE | (thd->variables.sql_mode & diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index e4a2595efed..31607d79e56 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -100,7 +100,7 @@ bool Item_func_sec_to_time::sec_to_time(my_decimal *seconds, MYSQL_TIME *ltime) my_decimal_mul(E_DEC_FATAL_ERROR, &tmp, &sub_seconds, &time_second_part_factor); (void) decimal2longlong(&tmp, &full_seconds); - ltime->second_part= full_seconds; + ltime->second_part= (ulong)full_seconds; return 0; diff --git a/sql/set_var.cc b/sql/set_var.cc index aac6746da82..4d14791a355 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -2915,7 +2915,7 @@ bool sys_var_timestamp::check(THD *thd, set_var *var) if (val < 0 || val > MY_TIME_T_MAX) { char buf[64]; - my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "timestamp", llstr(val, buf)); + my_error(ER_WRONG_VALUE_FOR_VAR, MYF(0), "timestamp", llstr((longlong)val, buf)); return TRUE; } var->save_result.ulonglong_value= hrtime_from_time(val); diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 56702a2308f..60f80fc52e8 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -580,8 +580,8 @@ uint32 String::numchars() int String::charpos(longlong i,uint32 offset) { if (i <= 0) - return i; - return str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,i); + return (int)i; + return (int)str_charset->cset->charpos(str_charset,Ptr+offset,Ptr+str_length,(size_t)i); } int String::strstr(const String &s,uint32 offset) diff --git a/storage/maria/tablockman.c b/storage/maria/tablockman.c index 1bb8889aaa7..eb494a8d19b 100644 --- a/storage/maria/tablockman.c +++ b/storage/maria/tablockman.c @@ -607,7 +607,7 @@ void tablockman_init(TABLOCKMAN *lm, loid_to_tlo_func *func, uint timeout) lm->loid_to_tlo= func; lm->lock_timeout= timeout; pthread_mutex_init(& lm->pool_mutex, MY_MUTEX_INIT_FAST); - my_getsystime(); /* ensure that my_getsystime() is initialized */ + my_interval_timer(); /* ensure that my_interval_timer() is initialized */ } void tablockman_destroy(TABLOCKMAN *lm) diff --git a/storage/pbxt/src/filesys_xt.cc b/storage/pbxt/src/filesys_xt.cc index 31e2cf961b6..ebe0ed146b0 100644 --- a/storage/pbxt/src/filesys_xt.cc +++ b/storage/pbxt/src/filesys_xt.cc @@ -369,8 +369,7 @@ xtPublic xtBool xt_fs_stat(XTThreadPtr self, char *path, off_t *size, struct tim CloseHandle(fh); if (size) *size = (off_t) info.nFileSizeLow | (((off_t) info.nFileSizeHigh) << 32); - if (mod_time) - mod_time->tv.ft = info.ftLastWriteTime; + memset(mod_time, 0, sizeof(*mod_time)); #else struct stat sb; diff --git a/storage/pbxt/src/pthread_xt.cc b/storage/pbxt/src/pthread_xt.cc index c5dc2e41fdd..9f35f50b8c7 100755 --- a/storage/pbxt/src/pthread_xt.cc +++ b/storage/pbxt/src/pthread_xt.cc @@ -396,48 +396,7 @@ xtPublic int xt_p_cond_wait(xt_cond_type *cond, xt_mutex_type *mutex) xtPublic int xt_p_cond_timedwait(xt_cond_type *cond, xt_mutex_type *mt, struct timespec *abstime) { - pthread_mutex_t *mutex = &mt->mt_cs; - int result; - long timeout; - union ft64 now; - - if (abstime != NULL) { - GetSystemTimeAsFileTime(&now.ft); - - timeout = (long)((abstime->tv.i64 - now.i64) / 10000); - if (timeout < 0) - timeout = 0L; - if (timeout > abstime->max_timeout_msec) - timeout = abstime->max_timeout_msec; - } - else - timeout= INFINITE; - - WaitForSingleObject(cond->broadcast_block_event, INFINITE); - - EnterCriticalSection(&cond->lock_waiting); - cond->waiting++; - LeaveCriticalSection(&cond->lock_waiting); - - LeaveCriticalSection(mutex); - - result= WaitForMultipleObjects(2, cond->events, FALSE, timeout); - - EnterCriticalSection(&cond->lock_waiting); - cond->waiting--; - - if (cond->waiting == 0) { - /* The last waiter must reset the broadcast - * state (whther there was a broadcast or not)! - */ - ResetEvent(cond->events[xt_cond_type::BROADCAST]); - SetEvent(cond->broadcast_block_event); - } - LeaveCriticalSection(&cond->lock_waiting); - - EnterCriticalSection(mutex); - - return result == WAIT_TIMEOUT ? ETIMEDOUT : 0; + return pthread_cond_timedwait(cond, &mt->mt_cs, abstime); } xtPublic int xt_p_join(pthread_t thread, void **value) diff --git a/storage/pbxt/src/thread_xt.cc b/storage/pbxt/src/thread_xt.cc index 52c2c6c29c5..eb9941f13fb 100644 --- a/storage/pbxt/src/thread_xt.cc +++ b/storage/pbxt/src/thread_xt.cc @@ -54,6 +54,9 @@ void xt_db_exit_thread(XTThreadPtr self); static void thr_accumulate_statistics(XTThreadPtr self); +#ifdef _WIN32 +#include <my_sys.h> +#endif /* * ----------------------------------------------------------------------- * THREAD GLOBALS @@ -1962,18 +1965,7 @@ xtPublic xtBool xt_timed_wait_cond(XTThreadPtr self, xt_cond_type *cond, xt_mute XTThreadPtr me = self ? self : xt_get_self(); #ifdef XT_WIN - union ft64 now; - - GetSystemTimeAsFileTime(&now.ft); - - /* System time is measured in 100ns units. - * This calculation will be reversed by the Windows implementation - * of pthread_cond_timedwait(), in order to extract the - * milli-second timeout! - */ - abstime.tv.i64 = now.i64 + (milli_sec * 10000); - - abstime.max_timeout_msec = milli_sec; + set_timespec_nsec(abstime, 1000000ULL* milli_sec); #else struct timeval now; u_llong micro_sec; |