summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2012-10-19 20:38:59 +0200
committerSergei Golubchik <sergii@pisem.net>2012-10-19 20:38:59 +0200
commite1f681c99b3e5462c033aaafa94ac295e626cde2 (patch)
tree2da5eff1a0d03831c2d85b32a7bc3df6ec37b522 /mysys
parent52c84d144d3b07966d9b3bab8694eb012eef69ce (diff)
parent807fef40fffbbb8e92564a52b902b504ba8cfcdc (diff)
downloadmariadb-git-e1f681c99b3e5462c033aaafa94ac295e626cde2.tar.gz
10.0-base -> 10.0-monty
Diffstat (limited to 'mysys')
-rw-r--r--mysys/charset-def.c2
-rw-r--r--mysys/lf_alloc-pin.c2
-rw-r--r--mysys/lf_hash.c4
-rw-r--r--mysys/mf_fn_ext.c37
-rw-r--r--mysys/mf_iocache2.c60
-rw-r--r--mysys/mf_radix.c5
-rw-r--r--mysys/mf_sort.c2
-rw-r--r--mysys/my_chsize.c7
-rw-r--r--mysys/my_getopt.c10
-rw-r--r--mysys/my_lock.c2
-rw-r--r--mysys/my_pthread.c69
-rw-r--r--mysys/my_rename.c16
-rw-r--r--mysys/my_sync.c18
-rw-r--r--mysys/my_write.c5
-rw-r--r--mysys/thr_mutex.c3
-rw-r--r--mysys/waiting_threads.c2
16 files changed, 134 insertions, 110 deletions
diff --git a/mysys/charset-def.c b/mysys/charset-def.c
index 4183b1fcd99..e9f2ecdea49 100644
--- a/mysys/charset-def.c
+++ b/mysys/charset-def.c
@@ -326,7 +326,7 @@ my_bool init_compiled_charsets(myf flags __attribute__((unused)))
add_compiled_collation(&my_charset_utf16_hungarian_uca_ci);
add_compiled_collation(&my_charset_utf16_sinhala_uca_ci);
add_compiled_collation(&my_charset_utf16_croatian_uca_ci);
-#endif /* HAVE_UCA_COLLATIOINS */
+#endif /* HAVE_UCA_COLLATIONS */
#endif /* HAVE_CHARSET_utf16 */
diff --git a/mysys/lf_alloc-pin.c b/mysys/lf_alloc-pin.c
index d23ef129aa2..6ab6ba3aae0 100644
--- a/mysys/lf_alloc-pin.c
+++ b/mysys/lf_alloc-pin.c
@@ -271,7 +271,7 @@ static int ptr_cmp(void **a, void **b)
void _lf_pinbox_free(LF_PINS *pins, void *addr)
{
add_to_purgatory(pins, addr);
- if (pins->purgatory_count % LF_PURGATORY_SIZE)
+ if (pins->purgatory_count % LF_PURGATORY_SIZE == 0)
_lf_pinbox_real_free(pins);
}
diff --git a/mysys/lf_hash.c b/mysys/lf_hash.c
index 83cfe1a1639..38b212c65f0 100644
--- a/mysys/lf_hash.c
+++ b/mysys/lf_hash.c
@@ -268,8 +268,10 @@ static LF_SLIST *lsearch(LF_SLIST * volatile *head, CHARSET_INFO *cs,
int res= lfind(head, cs, hashnr, key, keylen, &cursor, pins);
if (res)
_lf_pin(pins, 2, cursor.curr);
- _lf_unpin(pins, 0);
+ else
+ _lf_unpin(pins, 2);
_lf_unpin(pins, 1);
+ _lf_unpin(pins, 0);
return res ? cursor.curr : 0;
}
diff --git a/mysys/mf_fn_ext.c b/mysys/mf_fn_ext.c
index 47fc67cabbd..cbf0d5dd9e4 100644
--- a/mysys/mf_fn_ext.c
+++ b/mysys/mf_fn_ext.c
@@ -52,3 +52,40 @@ char *fn_ext(const char *name)
pos=strchr(gpos,FN_EXTCHAR);
DBUG_RETURN((char*) (pos ? pos : strend(gpos)));
} /* fn_ext */
+
+
+/*
+ Return a pointer to the extension of the filename.
+
+ SYNOPSIS
+ fn_ext()
+ name Name of file
+
+ DESCRIPTION
+ The extension is defined as everything after the last extension character
+ (normally '.') after the directory name.
+
+ RETURN VALUES
+ Pointer to to the extension character. If there isn't any extension,
+ points at the end ASCII(0) of the filename.
+*/
+
+char *fn_ext2(const char *name)
+{
+ register const char *pos, *gpos;
+ DBUG_ENTER("fn_ext");
+ DBUG_PRINT("mfunkt",("name: '%s'",name));
+
+#if defined(FN_DEVCHAR) || defined(BASKSLASH_MBTAIL)
+ {
+ char buff[FN_REFLEN];
+ size_t res_length;
+ gpos= name+ dirname_part(buff,(char*) name, &res_length);
+ }
+#else
+ if (!(gpos= strrchr(name, FN_LIBCHAR)))
+ gpos= name;
+#endif
+ pos=strrchr(gpos,FN_EXTCHAR);
+ DBUG_RETURN((char*) (pos ? pos : strend(gpos)));
+} /* fn_ext */
diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c
index 3c23d0737e7..ff05b7fa485 100644
--- a/mysys/mf_iocache2.c
+++ b/mysys/mf_iocache2.c
@@ -287,6 +287,40 @@ my_off_t my_b_filelength(IO_CACHE *info)
}
+size_t
+my_b_write_backtick_quote(IO_CACHE *info, const char *str, size_t len)
+{
+ const uchar *start;
+ const uchar *p= (const uchar *)str;
+ const uchar *end= p + len;
+ size_t count;
+ size_t total= 0;
+
+ if (my_b_write(info, (uchar *)"`", 1))
+ return (size_t)-1;
+ ++total;
+ for (;;)
+ {
+ start= p;
+ while (p < end && *p != '`')
+ ++p;
+ count= p - start;
+ if (count && my_b_write(info, start, count))
+ return (size_t)-1;
+ total+= count;
+ if (p >= end)
+ break;
+ if (my_b_write(info, (uchar *)"``", 2))
+ return (size_t)-1;
+ total+= 2;
+ ++p;
+ }
+ if (my_b_write(info, (uchar *)"`", 1))
+ return (size_t)-1;
+ ++total;
+ return total;
+}
+
/*
Simple printf version. Supports '%s', '%d', '%u', "%ld" and "%lu"
Used for logging in MySQL
@@ -311,6 +345,7 @@ size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
uint minimum_width_sign;
uint precision; /* as yet unimplemented for anything but %b */
my_bool is_zero_padded;
+ my_bool backtick_quoting;
/*
Store the location of the beginning of a format directive, for the
@@ -345,6 +380,7 @@ size_t my_b_vprintf(IO_CACHE *info, const char* fmt, va_list args)
fmt++;
is_zero_padded= FALSE;
+ backtick_quoting= FALSE;
minimum_width_sign= 1;
minimum_width= 0;
precision= 0;
@@ -357,6 +393,8 @@ process_flags:
minimum_width_sign= -1; fmt++; goto process_flags;
case '0':
is_zero_padded= TRUE; fmt++; goto process_flags;
+ case '`':
+ backtick_quoting= TRUE; fmt++; goto process_flags;
case '#':
/** @todo Implement "#" conversion flag. */ fmt++; goto process_flags;
case ' ':
@@ -400,9 +438,19 @@ process_flags:
reg2 char *par = va_arg(args, char *);
size_t length2 = strlen(par);
/* TODO: implement precision */
- out_length+= length2;
- if (my_b_write(info, (uchar*) par, length2))
- goto err;
+ if (backtick_quoting)
+ {
+ size_t total= my_b_write_backtick_quote(info, par, length2);
+ if (total == (size_t)-1)
+ goto err;
+ out_length+= total;
+ }
+ else
+ {
+ out_length+= length2;
+ if (my_b_write(info, (uchar*) par, length2))
+ goto err;
+ }
}
else if (*fmt == 'b') /* Sized buffer parameter, only precision makes sense */
{
@@ -433,7 +481,11 @@ process_flags:
memset(buffz, '0', minimum_width - length2);
else
memset(buffz, ' ', minimum_width - length2);
- my_b_write(info, buffz, minimum_width - length2);
+ if (my_b_write(info, buffz, minimum_width - length2))
+ {
+ my_afree(buffz);
+ goto err;
+ }
my_afree(buffz);
}
diff --git a/mysys/mf_radix.c b/mysys/mf_radix.c
index 582ca76b8f8..2df1220acdd 100644
--- a/mysys/mf_radix.c
+++ b/mysys/mf_radix.c
@@ -25,6 +25,11 @@
/* Radixsort */
+my_bool radixsort_is_appliccable(uint n_items, size_t size_of_element)
+{
+ return size_of_element <= 20 && n_items >= 1000 && n_items < 100000;
+}
+
void radixsort_for_str_ptr(uchar **base, uint number_of_elements, size_t size_of_element, uchar **buffer)
{
uchar **end,**ptr,**buffer_ptr;
diff --git a/mysys/mf_sort.c b/mysys/mf_sort.c
index 9ef02787716..b2c58c26624 100644
--- a/mysys/mf_sort.c
+++ b/mysys/mf_sort.c
@@ -23,7 +23,7 @@ void my_string_ptr_sort(uchar *base, uint items, size_t size)
#if INT_MAX > 65536L
uchar **ptr=0;
- if (size <= 20 && items >= 1000 && items < 100000 &&
+ if (radixsort_is_appliccable(items, size) &&
(ptr= (uchar**) my_malloc(items*sizeof(char*),MYF(0))))
{
radixsort_for_str_ptr((uchar**) base,items,size,ptr);
diff --git a/mysys/my_chsize.c b/mysys/my_chsize.c
index 97ecd881af1..63964916d6f 100644
--- a/mysys/my_chsize.c
+++ b/mysys/my_chsize.c
@@ -67,13 +67,6 @@ int my_chsize(File fd, my_off_t newlength, int filler, myf MyFlags)
goto err;
}
DBUG_RETURN(0);
-#elif defined(HAVE_CHSIZE)
- if (chsize(fd, (off_t) newlength))
- {
- my_errno=errno;
- goto err;
- }
- DBUG_RETURN(0);
#else
/*
Fill space between requested length and true length with 'filler'
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index facc1569943..c1b0a129a30 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -691,15 +691,13 @@ static int setval(const struct my_option *opts, void *value, char *argument,
*((double*) value)= getopt_double(argument, opts, &err);
break;
case GET_STR:
- if (argument == enabled_my_option)
- break; /* string options don't use this default of "1" */
- *((char**) value)= argument;
+ /* If no argument or --enable-string-option, set string to "" */
+ *((char**) value)= argument == enabled_my_option ? (char*) "" : argument;
break;
case GET_STR_ALLOC:
- if (argument == enabled_my_option)
- break; /* string options don't use this default of "1" */
my_free(*((char**) value));
- if (!(*((char**) value)= my_strdup(argument, MYF(MY_WME))))
+ if (!(*((char**) value)= my_strdup(argument == enabled_my_option ? "" :
+ argument, MYF(MY_WME))))
{
res= EXIT_OUT_OF_MEMORY;
goto ret;
diff --git a/mysys/my_lock.c b/mysys/my_lock.c
index c9e599904fa..54ec3838b58 100644
--- a/mysys/my_lock.c
+++ b/mysys/my_lock.c
@@ -212,7 +212,7 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
if (lockf(fd,locktype,length) != -1)
DBUG_RETURN(0);
#endif /* HAVE_FCNTL */
-#endif /* HAVE_LOCKING */
+#endif /* _WIN32 */
/* We got an error. We don't want EACCES errors */
my_errno=(errno == EACCES) ? EAGAIN : errno ? errno : -1;
diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c
index d29cbcc5048..20e53a23ab5 100644
--- a/mysys/my_pthread.c
+++ b/mysys/my_pthread.c
@@ -30,20 +30,6 @@
uint thd_lib_detected= 0;
-/* To allow use of pthread_getspecific with two arguments */
-
-#ifdef HAVE_NONPOSIX_PTHREAD_GETSPECIFIC
-#undef pthread_getspecific
-
-void *my_pthread_getspecific_imp(pthread_key_t key)
-{
- void *value;
- if (pthread_getspecific(key,(void *) &value))
- return 0;
- return value;
-}
-#endif
-
/*
Some functions for RTS threads, AIX, Siemens Unix and UnixWare 7
(and DEC OSF/1 3.2 too)
@@ -51,18 +37,6 @@ void *my_pthread_getspecific_imp(pthread_key_t key)
int my_pthread_create_detached=1;
-#if defined(HAVE_NONPOSIX_SIGWAIT) || defined(HAVE_DEC_3_2_THREADS)
-
-int my_sigwait(const sigset_t *set,int *sig)
-{
- int signal=sigwait((sigset_t*) set);
- if (signal < 0)
- return errno;
- *sig=signal;
- return 0;
-}
-#endif
-
/* localtime_r for SCO 3.2V4.2 */
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
@@ -117,7 +91,7 @@ struct tm *gmtime_r(const time_t *clock, struct tm *res)
** Author: Gary Wisniewski <garyw@spidereye.com.au>, much modified by Monty
****************************************************************************/
-#if !defined(HAVE_SIGWAIT) && !defined(sigwait) && !defined(__WIN__) && !defined(HAVE_rts_threads) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS)
+#if !defined(HAVE_SIGWAIT) && !defined(sigwait) && !defined(__WIN__) && !defined(HAVE_rts_threads)
#if !defined(DONT_USE_SIGSUSPEND)
@@ -269,13 +243,7 @@ void *sigwait_thread(void *set_arg)
for (;;)
{ /* Wait for signals */
-#ifdef HAVE_NOT_BROKEN_SELECT
- fd_set fd;
- FD_ZERO(&fd);
- select(0,&fd,0,0,0);
-#else
sleep(1); /* Because of broken BSDI */
-#endif
}
}
@@ -352,39 +320,6 @@ int sigwait(sigset_t *setp, int *sigp)
#undef pthread_attr_getstacksize
/*****************************************************************************
-** Patches for AIX and DEC OSF/1 3.2
-*****************************************************************************/
-
-#if defined(HAVE_NONPOSIX_PTHREAD_MUTEX_INIT)
-
-#include <netdb.h>
-
-int my_pthread_mutex_noposix_init(pthread_mutex_t *mp,
- const pthread_mutexattr_t *attr)
-{
- int error;
- if (!attr)
- error=pthread_mutex_init(mp,pthread_mutexattr_default);
- else
- error=pthread_mutex_init(mp,*attr);
- return error;
-}
-
-int my_pthread_cond_noposix_init(pthread_cond_t *mp,
- const pthread_condattr_t *attr)
-{
- int error;
- if (!attr)
- error=pthread_cond_init(mp,pthread_condattr_default);
- else
- error=pthread_cond_init(mp,*attr);
- return error;
-}
-
-#endif
-
-
-/*****************************************************************************
Patches for HPUX
We need these because the pthread_mutex.. code returns -1 on error,
instead of the error code.
@@ -394,7 +329,7 @@ int my_pthread_cond_noposix_init(pthread_cond_t *mp,
this has to be added here.
****************************************************************************/
-#if defined(HPUX10) || defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT)
+#if defined(HPUX10)
int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
struct timespec *abstime)
diff --git a/mysys/my_rename.c b/mysys/my_rename.c
index 6704d7c87d0..b89bc4c8fbd 100644
--- a/mysys/my_rename.c
+++ b/mysys/my_rename.c
@@ -27,22 +27,6 @@ int my_rename(const char *from, const char *to, myf MyFlags)
DBUG_ENTER("my_rename");
DBUG_PRINT("my",("from %s to %s MyFlags %d", from, to, MyFlags));
-#if defined(HAVE_FILE_VERSIONS)
- { /* Check that there isn't a old file */
- int save_errno;
- MY_STAT my_stat_result;
- save_errno=my_errno;
- if (my_stat(to,&my_stat_result,MYF(0)))
- {
- my_errno=EEXIST;
- error= -1;
- if (MyFlags & MY_FAE+MY_WME)
- my_error(EE_LINK, MYF(ME_BELL+ME_WAITTANG),from,to,my_errno);
- DBUG_RETURN(error);
- }
- my_errno=save_errno;
- }
-#endif
#if defined(HAVE_RENAME)
#if defined(__WIN__)
/*
diff --git a/mysys/my_sync.c b/mysys/my_sync.c
index 3853d30632e..88bcb685271 100644
--- a/mysys/my_sync.c
+++ b/mysys/my_sync.c
@@ -49,6 +49,13 @@ void thr_set_sync_wait_callback(void (*before_wait)(void),
(which is correct behaviour, if we know that the other thread synced the
file before closing)
+ MY_SYNC_FILESIZE is useful when syncing a file after it has been extended.
+ On Linux, fdatasync() on ext3/ext4 file systems does not properly flush
+ to disk the inode data required to preserve the added data across a crash
+ (this looks to be a bug). But when a file is extended, inode data will most
+ likely need flushing in any case, so passing MY_SYNC_FILESIZE as flags
+ is not likely to be any slower, and will be crash safe on Linux ext3/ext4.
+
RETURN
0 ok
-1 error
@@ -84,8 +91,12 @@ int my_sync(File fd, myf my_flags)
DBUG_PRINT("info",("fcntl(F_FULLFSYNC) failed, falling back"));
#endif
#if defined(HAVE_FDATASYNC) && HAVE_DECL_FDATASYNC
- res= fdatasync(fd);
-#elif defined(HAVE_FSYNC)
+ if (!(my_flags & MY_SYNC_FILESIZE))
+ res= fdatasync(fd);
+ else
+ {
+#endif
+#if defined(HAVE_FSYNC)
res= fsync(fd);
if (res == -1 && errno == ENOLCK)
res= 0; /* Result Bug in Old FreeBSD */
@@ -95,6 +106,9 @@ int my_sync(File fd, myf my_flags)
#error Cannot find a way to sync a file, durability in danger
res= 0; /* No sync (strange OS) */
#endif
+#if defined(HAVE_FDATASYNC) && HAVE_DECL_FDATASYNC
+ }
+#endif
} while (res == -1 && errno == EINTR);
if (res)
diff --git a/mysys/my_write.c b/mysys/my_write.c
index dc04b60f613..c4cba7a927d 100644
--- a/mysys/my_write.c
+++ b/mysys/my_write.c
@@ -47,6 +47,11 @@ size_t my_write(File Filedes, const uchar *Buffer, size_t Count, myf MyFlags)
#else
writtenbytes= write(Filedes, Buffer, Count);
#endif
+ DBUG_EXECUTE_IF("simulate_file_write_error",
+ {
+ errno= ENOSPC;
+ writtenbytes= (size_t) -1;
+ });
if (writtenbytes == Count)
break;
if (writtenbytes != (size_t) -1)
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index 45f4220c835..17cda782b30 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -43,9 +43,6 @@
#undef pthread_cond_wait
#undef pthread_cond_timedwait
#undef safe_mutex_free_deadlock_data
-#ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT
-#define pthread_mutex_init(a,b) my_pthread_noposix_mutex_init((a),(b))
-#endif
#endif /* DO_NOT_REMOVE_THREAD_WRAPPERS */
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
diff --git a/mysys/waiting_threads.c b/mysys/waiting_threads.c
index f7e74e012d2..0a9474e68b4 100644
--- a/mysys/waiting_threads.c
+++ b/mysys/waiting_threads.c
@@ -193,7 +193,9 @@ uint32 wt_success_stats;
static my_atomic_rwlock_t cycle_stats_lock, wait_stats_lock, success_stats_lock;
+#ifdef HAVE_PSI_INTERFACE
extern PSI_cond_key key_WT_RESOURCE_cond;
+#endif
#ifdef SAFE_STATISTICS
#define incr(VAR, LOCK) \