diff options
author | Mikael Ronstrom <mikael@dator8> | 2011-01-12 14:43:03 +0100 |
---|---|---|
committer | Mikael Ronstrom <mikael@dator8> | 2011-01-12 14:43:03 +0100 |
commit | 773267552f6c701cf3210f908a3608ad0da1087f (patch) | |
tree | 2572fe5a1f81ea6ca0b1fa3d47f468b568ff5503 /mysys | |
parent | 7dae4282d4d5ec2ec8d17f600e87918e0a0aea00 (diff) | |
parent | bbf40ba3c5cac76b4efd2dc177b9ffaff1ce9266 (diff) | |
download | mariadb-git-773267552f6c701cf3210f908a3608ad0da1087f.tar.gz |
merge
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/mf_brkhant.c | 72 | ||||
-rw-r--r-- | mysys/mf_iocache.c | 39 | ||||
-rw-r--r-- | mysys/mf_iocache2.c | 5 | ||||
-rw-r--r-- | mysys/mf_keycache.c | 77 | ||||
-rw-r--r-- | mysys/mf_keycaches.c | 2 | ||||
-rw-r--r-- | mysys/my_bitmap.c | 22 | ||||
-rw-r--r-- | mysys/my_fopen.c | 134 | ||||
-rw-r--r-- | mysys/my_fstream.c | 3 | ||||
-rw-r--r-- | mysys/my_gethostbyname.c | 2 | ||||
-rw-r--r-- | mysys/my_getopt.c | 20 | ||||
-rw-r--r-- | mysys/my_getsystime.c | 8 | ||||
-rw-r--r-- | mysys/my_init.c | 19 | ||||
-rw-r--r-- | mysys/my_lib.c | 15 | ||||
-rw-r--r-- | mysys/my_open.c | 6 | ||||
-rw-r--r-- | mysys/my_pread.c | 8 | ||||
-rw-r--r-- | mysys/my_pthread.c | 2 | ||||
-rw-r--r-- | mysys/my_read.c | 4 | ||||
-rw-r--r-- | mysys/my_static.c | 4 | ||||
-rw-r--r-- | mysys/my_thr_init.c | 2 | ||||
-rw-r--r-- | mysys/my_write.c | 3 | ||||
-rw-r--r-- | mysys/mysys_priv.h | 4 | ||||
-rw-r--r-- | mysys/thr_alarm.c | 15 | ||||
-rw-r--r-- | mysys/thr_lock.c | 13 | ||||
-rw-r--r-- | mysys/thr_mutex.c | 8 | ||||
-rw-r--r-- | mysys/thr_rwlock.c | 2 |
25 files changed, 211 insertions, 278 deletions
diff --git a/mysys/mf_brkhant.c b/mysys/mf_brkhant.c deleted file mode 100644 index 3573b9973b2..00000000000 --- a/mysys/mf_brkhant.c +++ /dev/null @@ -1,72 +0,0 @@ -/* Copyright (C) 2000 MySQL 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; version 2 of the License. - - 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 */ - -/* Dont let the user break when you are doing something important */ -/* Remembers if it got 'SIGINT' and executes it on allow_break */ -/* A static buffer is used; don't call dont_break() twice in a row */ - -#include "mysys_priv.h" -#include "my_static.h" - - /* Set variable that we can't break */ - -#if !defined(THREAD) -void dont_break(void) -{ - my_dont_interrupt=1; - return; -} /* dont_break */ - -void allow_break(void) -{ - { - reg1 int index; - - my_dont_interrupt=0; - if (_my_signals) - { - if (_my_signals > MAX_SIGNALS) - _my_signals=MAX_SIGNALS; - for (index=0 ; index < _my_signals ; index++) - { - if (_my_sig_remember[index].func) /* Safequard */ - { - (*_my_sig_remember[index].func)(_my_sig_remember[index].number); - _my_sig_remember[index].func=0; - } - } - _my_signals=0; - } - } -} /* dont_break */ -#endif - - /* Set old status */ - -#if !defined(THREAD) -void my_remember_signal(int signal_number, sig_handler (*func) (int)) -{ -#ifndef __WIN__ - reg1 int index; - - index=_my_signals++; /* Nobody can break a ++ ? */ - if (index < MAX_SIGNALS) - { - _my_sig_remember[index].number=signal_number; - _my_sig_remember[index].func=func; - } -#endif /* __WIN__ */ -} /* my_remember_signal */ -#endif /* THREAD */ diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index 575581712d4..62e51ffb629 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -55,15 +55,10 @@ static void my_aiowait(my_aio_result *result); #endif #include <errno.h> -#ifdef THREAD #define lock_append_buffer(info) \ mysql_mutex_lock(&(info)->append_buffer_lock) #define unlock_append_buffer(info) \ mysql_mutex_unlock(&(info)->append_buffer_lock) -#else -#define lock_append_buffer(info) -#define unlock_append_buffer(info) -#endif #define IO_ROUND_UP(X) (((X)+IO_SIZE-1) & ~(IO_SIZE-1)) #define IO_ROUND_DN(X) ( (X) & ~(IO_SIZE-1)) @@ -116,11 +111,7 @@ init_functions(IO_CACHE* info) info->write_function = 0; /* Force a core if used */ break; default: - info->read_function = -#ifdef THREAD - info->share ? _my_b_read_r : -#endif - _my_b_read; + info->read_function = info->share ? _my_b_read_r : _my_b_read; info->write_function = _my_b_write; } @@ -193,9 +184,7 @@ int init_io_cache(IO_CACHE *info, File file, size_t cachesize, } info->disk_writes= 0; -#ifdef THREAD info->share=0; -#endif if (!cachesize && !(cachesize= my_default_record_cache_size)) DBUG_RETURN(1); /* No cache requested */ @@ -263,12 +252,10 @@ int init_io_cache(IO_CACHE *info, File file, size_t cachesize, { info->append_read_pos = info->write_pos = info->write_buffer; info->write_end = info->write_buffer + info->buffer_length; -#ifdef THREAD mysql_mutex_init(key_IO_CACHE_append_buffer_lock, &info->append_buffer_lock, MY_MUTEX_INIT_FAST); -#endif } -#if defined(SAFE_MUTEX) && defined(THREAD) +#if defined(SAFE_MUTEX) else { /* Clear mutex so that safe_mutex will notice that it's not initialized */ @@ -601,7 +588,6 @@ int _my_b_read(register IO_CACHE *info, uchar *Buffer, size_t Count) } -#ifdef THREAD /* Prepare IO_CACHE for shared use. @@ -1162,7 +1148,6 @@ static void copy_to_read_buffer(IO_CACHE *write_cache, write_length-= copy_length; } } -#endif /*THREAD*/ /* @@ -1579,7 +1564,6 @@ int _my_b_write(register IO_CACHE *info, const uchar *Buffer, size_t Count) if (mysql_file_write(info->file, Buffer, length, info->myflags | MY_NABP)) return info->error= -1; -#ifdef THREAD /* In case of a shared I/O cache with a writer we normally do direct write cache to read cache copy. Simulate this here by direct @@ -1593,7 +1577,6 @@ int _my_b_write(register IO_CACHE *info, const uchar *Buffer, size_t Count) */ if (info->share) copy_to_read_buffer(info, Buffer, length); -#endif Count-=length; Buffer+=length; @@ -1615,13 +1598,11 @@ int my_b_append(register IO_CACHE *info, const uchar *Buffer, size_t Count) { size_t rest_length,length; -#ifdef THREAD /* Assert that we cannot come here with a shared cache. If we do one day, we might need to add a call to copy_to_read_buffer(). */ DBUG_ASSERT(!info->share); -#endif lock_append_buffer(info); rest_length= (size_t) (info->write_end - info->write_pos); @@ -1683,13 +1664,11 @@ int my_block_write(register IO_CACHE *info, const uchar *Buffer, size_t Count, size_t length; int error=0; -#ifdef THREAD /* Assert that we cannot come here with a shared cache. If we do one day, we might need to add a call to copy_to_read_buffer(). */ DBUG_ASSERT(!info->share); -#endif if (pos < info->pos_in_file) { @@ -1735,16 +1714,10 @@ int my_block_write(register IO_CACHE *info, const uchar *Buffer, size_t Count, /* Flush write cache */ -#ifdef THREAD #define LOCK_APPEND_BUFFER if (need_append_buffer_lock) \ lock_append_buffer(info); #define UNLOCK_APPEND_BUFFER if (need_append_buffer_lock) \ unlock_append_buffer(info); -#else -#define LOCK_APPEND_BUFFER -#define UNLOCK_APPEND_BUFFER -#endif - int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock __attribute__((unused))) @@ -1755,10 +1728,8 @@ int my_b_flush_io_cache(IO_CACHE *info, DBUG_ENTER("my_b_flush_io_cache"); DBUG_PRINT("enter", ("cache: 0x%lx", (long) info)); -#ifdef THREAD if (!append_cache) need_append_buffer_lock= 0; -#endif if (info->type == WRITE_CACHE || append_cache) { @@ -1771,7 +1742,6 @@ int my_b_flush_io_cache(IO_CACHE *info, if ((length=(size_t) (info->write_pos - info->write_buffer))) { -#ifdef THREAD /* In case of a shared I/O cache with a writer we do direct write cache to read cache copy. Do it before the write here so that @@ -1780,7 +1750,6 @@ int my_b_flush_io_cache(IO_CACHE *info, */ if (info->share) copy_to_read_buffer(info, info->write_buffer, length); -#endif pos_in_file=info->pos_in_file; /* @@ -1859,13 +1828,11 @@ int end_io_cache(IO_CACHE *info) DBUG_ENTER("end_io_cache"); DBUG_PRINT("enter",("cache: 0x%lx", (ulong) info)); -#ifdef THREAD /* Every thread must call remove_io_thread(). The last one destroys the share elements. */ DBUG_ASSERT(!info->share || !info->share->total_threads); -#endif if ((pre_close=info->pre_close)) { @@ -1884,9 +1851,7 @@ int end_io_cache(IO_CACHE *info) { /* Destroy allocated mutex */ info->type= TYPE_NOT_SET; -#ifdef THREAD mysql_mutex_destroy(&info->append_buffer_lock); -#endif } DBUG_RETURN(error); } /* end_io_cache */ diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c index 7a40ea8a86f..8962a037da0 100644 --- a/mysys/mf_iocache2.c +++ b/mysys/mf_iocache2.c @@ -90,9 +90,8 @@ my_off_t my_b_append_tell(IO_CACHE* info) from messing with the variables that we need in order to provide the answer to the question. */ -#ifdef THREAD mysql_mutex_lock(&info->append_buffer_lock); -#endif + #ifndef DBUG_OFF /* Make sure EOF is where we think it is. Note that we cannot just use @@ -112,9 +111,7 @@ my_off_t my_b_append_tell(IO_CACHE* info) } #endif res = info->end_of_file + (info->write_pos-info->append_read_pos); -#ifdef THREAD mysql_mutex_unlock(&info->append_buffer_lock); -#endif return res; } diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index 9993c636fb1..42cdea65f34 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -225,14 +225,11 @@ KEY_CACHE *dflt_key_cache= &dflt_key_cache_var; #define FLUSH_CACHE 2000 /* sort this many blocks at once */ static int flush_all_key_blocks(KEY_CACHE *keycache); -#ifdef THREAD + static void wait_on_queue(KEYCACHE_WQUEUE *wqueue, mysql_mutex_t *mutex); static void release_whole_queue(KEYCACHE_WQUEUE *wqueue); -#else -#define wait_on_queue(wqueue, mutex) do {} while (0) -#define release_whole_queue(wqueue) do {} while (0) -#endif + static void free_block(KEY_CACHE *keycache, BLOCK_LINK *block); #if !defined(DBUG_OFF) static void test_key_cache(KEY_CACHE *keycache, @@ -285,7 +282,7 @@ static void keycache_debug_print(const char *fmt,...); #endif /* defined(KEYCACHE_DEBUG_LOG) && defined(KEYCACHE_DEBUG) */ #if defined(KEYCACHE_DEBUG) || !defined(DBUG_OFF) -#ifdef THREAD + static long keycache_thread_id; #define KEYCACHE_THREAD_TRACE(l) \ KEYCACHE_DBUG_PRINT(l,("|thread %ld",keycache_thread_id)) @@ -297,11 +294,6 @@ static long keycache_thread_id; #define KEYCACHE_THREAD_TRACE_END(l) \ KEYCACHE_DBUG_PRINT(l,("]thread %ld",keycache_thread_id)) -#else /* THREAD */ -#define KEYCACHE_THREAD_TRACE(l) KEYCACHE_DBUG_PRINT(l,("")) -#define KEYCACHE_THREAD_TRACE_BEGIN(l) KEYCACHE_DBUG_PRINT(l,("")) -#define KEYCACHE_THREAD_TRACE_END(l) KEYCACHE_DBUG_PRINT(l,("")) -#endif /* THREAD */ #else #define KEYCACHE_THREAD_TRACE_BEGIN(l) #define KEYCACHE_THREAD_TRACE_END(l) @@ -583,7 +575,6 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, keycache_pthread_mutex_lock(&keycache->cache_lock); -#ifdef THREAD /* We may need to wait for another thread which is doing a resize already. This cannot happen in the MySQL server though. It allows @@ -596,7 +587,6 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, wait_on_queue(&keycache->resize_queue, &keycache->cache_lock); /* purecov: end */ } -#endif /* Mark the operation in progress. This blocks other threads from doing @@ -625,7 +615,6 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, keycache->resize_in_flush= 0; } -#ifdef THREAD /* Some direct read/write operations (bypassing the cache) may still be unfinished. Wait until they are done. If the key cache can be used, @@ -639,9 +628,6 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size, */ while (keycache->cnt_for_resize_op) wait_on_queue(&keycache->waiting_for_resize_cnt, &keycache->cache_lock); -#else - KEYCACHE_DBUG_ASSERT(keycache->cnt_for_resize_op == 0); -#endif /* Free old cache structures, allocate new structures, and initialize @@ -782,8 +768,6 @@ void end_key_cache(KEY_CACHE *keycache, my_bool cleanup) } /* end_key_cache */ -#ifdef THREAD - /* Link a thread into double-linked queue of waiting threads. @@ -963,8 +947,6 @@ static void release_whole_queue(KEYCACHE_WQUEUE *wqueue) wqueue->last_thread= NULL; } -#endif /* THREAD */ - /* Unlink a block from the chain of dirty/clean blocks @@ -1136,7 +1118,7 @@ static void link_block(KEY_CACHE *keycache, BLOCK_LINK *block, my_bool hot, DBUG_ASSERT(block->prev_changed && *block->prev_changed == block); DBUG_ASSERT(!block->next_used); DBUG_ASSERT(!block->prev_used); -#ifdef THREAD + if (!hot && keycache->waiting_for_block.last_thread) { /* Signal that in the LRU warm sub-chain an available block has appeared */ @@ -1196,10 +1178,7 @@ static void link_block(KEY_CACHE *keycache, BLOCK_LINK *block, my_bool hot, #endif return; } -#else /* THREAD */ - KEYCACHE_DBUG_ASSERT(! (!hot && keycache->waiting_for_block.last_thread)); - /* Condition not transformed using DeMorgan, to keep the text identical */ -#endif /* THREAD */ + pins= hot ? &keycache->used_ins : &keycache->used_last; ins= *pins; if (ins) @@ -1421,12 +1400,9 @@ static void remove_reader(BLOCK_LINK *block) DBUG_ASSERT(!block->next_used); DBUG_ASSERT(!block->prev_used); DBUG_ASSERT(block->hash_link->requests); -#ifdef THREAD + if (! --block->hash_link->requests && block->condvar) keycache_pthread_cond_signal(block->condvar); -#else - --block->hash_link->requests; -#endif } @@ -1438,7 +1414,6 @@ static void remove_reader(BLOCK_LINK *block) static void wait_for_readers(KEY_CACHE *keycache, BLOCK_LINK *block) { -#ifdef THREAD struct st_my_thread_var *thread= my_thread_var; DBUG_ASSERT(block->status & (BLOCK_READ | BLOCK_IN_USE)); DBUG_ASSERT(!(block->status & (BLOCK_IN_FLUSH | BLOCK_CHANGED))); @@ -1460,9 +1435,6 @@ static void wait_for_readers(KEY_CACHE *keycache, keycache_pthread_cond_wait(&thread->suspend, &keycache->cache_lock); block->condvar= NULL; } -#else - KEYCACHE_DBUG_ASSERT(block->hash_link->requests == 0); -#endif } @@ -1492,7 +1464,7 @@ static void unlink_hash(KEY_CACHE *keycache, HASH_LINK *hash_link) if ((*hash_link->prev= hash_link->next)) hash_link->next->prev= hash_link->prev; hash_link->block= NULL; -#ifdef THREAD + if (keycache->waiting_for_hash_link.last_thread) { /* Signal that a free hash link has appeared */ @@ -1528,9 +1500,6 @@ static void unlink_hash(KEY_CACHE *keycache, HASH_LINK *hash_link) hash_link); return; } -#else /* THREAD */ - KEYCACHE_DBUG_ASSERT(! (keycache->waiting_for_hash_link.last_thread)); -#endif /* THREAD */ hash_link->next= keycache->free_hash_list; keycache->free_hash_list= hash_link; } @@ -1595,7 +1564,6 @@ restart: } else { -#ifdef THREAD /* Wait for a free hash link */ struct st_my_thread_var *thread= my_thread_var; KEYCACHE_PAGE page; @@ -1609,9 +1577,6 @@ restart: keycache_pthread_cond_wait(&thread->suspend, &keycache->cache_lock); thread->opt_info= NULL; -#else - KEYCACHE_DBUG_ASSERT(0); -#endif goto restart; } hash_link->file= file; @@ -1731,7 +1696,6 @@ restart: - block assigned but not yet read from file (invalid data). */ -#ifdef THREAD if (keycache->in_resize) { /* This is a request during a resize operation */ @@ -1973,9 +1937,6 @@ restart: } DBUG_RETURN(0); } -#else /* THREAD */ - DBUG_ASSERT(!keycache->in_resize); -#endif if (page_status == PAGE_READ && (block->status & (BLOCK_IN_EVICTION | BLOCK_IN_SWITCH | @@ -2105,7 +2066,6 @@ restart: from the LRU ring. */ -#ifdef THREAD if (! keycache->used_last) { /* @@ -2138,9 +2098,7 @@ restart: DBUG_ASSERT(!hash_link->block->next_used); DBUG_ASSERT(!hash_link->block->prev_used); } -#else - KEYCACHE_DBUG_ASSERT(keycache->used_last); -#endif + /* If we waited above, hash_link->block has been assigned by link_block(). Otherwise it is still NULL. In the latter case @@ -2610,10 +2568,8 @@ uchar *key_cache_read(KEY_CACHE *keycache, set_if_smaller(read_length, keycache->key_cache_block_size-offset); KEYCACHE_DBUG_ASSERT(read_length > 0); -#ifndef THREAD if (block_length > keycache->key_cache_block_size || offset) return_buffer=0; -#endif /* Request the cache block that matches file/pos. */ keycache->global_cache_r_requests++; @@ -2673,9 +2629,6 @@ uchar *key_cache_read(KEY_CACHE *keycache, /* block status may have added BLOCK_ERROR in the above 'if'. */ if (!(block->status & BLOCK_ERROR)) { -#ifndef THREAD - if (! return_buffer) -#endif { DBUG_ASSERT(block->status & (BLOCK_READ | BLOCK_IN_USE)); #if !defined(SERIALIZED_READ_FROM_CACHE) @@ -2714,20 +2667,6 @@ uchar *key_cache_read(KEY_CACHE *keycache, break; } -#ifndef THREAD - /* This is only true if we where able to read everything in one block */ - if (return_buffer) - { - if (MYSQL_KEYCACHE_READ_DONE_ENABLED()) - { - MYSQL_KEYCACHE_READ_DONE((ulong) (keycache->blocks_used * - keycache->key_cache_block_size), - (ulong) (keycache->blocks_unused * - keycache->key_cache_block_size)); - } - DBUG_RETURN(block->buffer); - } -#endif next_block: buff+= read_length; filepos+= read_length+offset; diff --git a/mysys/mf_keycaches.c b/mysys/mf_keycaches.c index ee4ad025b0b..93b7eab4561 100644 --- a/mysys/mf_keycaches.c +++ b/mysys/mf_keycaches.c @@ -53,9 +53,7 @@ typedef struct st_safe_hash_entry typedef struct st_safe_hash_with_default { -#ifdef THREAD rw_lock_t mutex; -#endif HASH hash; uchar *default_value; SAFE_HASH_ENTRY *root; diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c index 3401c7301e9..dc15014121b 100644 --- a/mysys/my_bitmap.c +++ b/mysys/my_bitmap.c @@ -22,9 +22,6 @@ * the internal size is a set of 32 bit words * the number of bits specified in creation can be any number > 0 * there are THREAD safe versions of most calls called bitmap_lock_* - many of those are not used and not compiled normally but the code - already exist for them in an #ifdef:ed part. These can only be used - if THREAD was specified in bitmap_init TODO: Make assembler THREAD safe versions of these using test-and-set instructions @@ -85,18 +82,14 @@ void create_last_word_mask(MY_BITMAP *map) static inline void bitmap_lock(MY_BITMAP *map __attribute__((unused))) { -#ifdef THREAD if (map->mutex) mysql_mutex_lock(map->mutex); -#endif } static inline void bitmap_unlock(MY_BITMAP *map __attribute__((unused))) { -#ifdef THREAD if (map->mutex) mysql_mutex_unlock(map->mutex); -#endif } @@ -108,30 +101,30 @@ my_bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits, { uint size_in_bytes= bitmap_buffer_size(n_bits); uint extra= 0; -#ifdef THREAD + if (thread_safe) { size_in_bytes= ALIGN_SIZE(size_in_bytes); extra= sizeof(mysql_mutex_t); } map->mutex= 0; -#endif + if (!(buf= (my_bitmap_map*) my_malloc(size_in_bytes+extra, MYF(MY_WME)))) DBUG_RETURN(1); -#ifdef THREAD + if (thread_safe) { map->mutex= (mysql_mutex_t *) ((char*) buf + size_in_bytes); mysql_mutex_init(key_BITMAP_mutex, map->mutex, MY_MUTEX_INIT_FAST); } -#endif + } -#ifdef THREAD + else { DBUG_ASSERT(thread_safe == 0); } -#endif + map->bitmap= buf; map->n_bits= n_bits; @@ -146,10 +139,9 @@ void bitmap_free(MY_BITMAP *map) DBUG_ENTER("bitmap_free"); if (map->bitmap) { -#ifdef THREAD if (map->mutex) mysql_mutex_destroy(map->mutex); -#endif + my_free(map->bitmap); map->bitmap=0; } diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c index 861e4380690..e184c8308fc 100644 --- a/mysys/my_fopen.c +++ b/mysys/my_fopen.c @@ -18,6 +18,10 @@ #include <errno.h> #include "mysys_err.h" +#if defined(__FreeBSD__) +extern int getosreldate(void); +#endif + static void make_ftype(char * to,int flag); /* @@ -89,7 +93,135 @@ FILE *my_fopen(const char *filename, int flags, myf MyFlags) } /* my_fopen */ - /* Close a stream */ +#if defined(_WIN32) + +static FILE *my_win_freopen(const char *path, const char *mode, FILE *stream) +{ + int handle_fd, fd= _fileno(stream); + HANDLE osfh; + + DBUG_ASSERT(path && stream); + + /* Services don't have stdout/stderr on Windows, so _fileno returns -1. */ + if (fd < 0) + { + if (!freopen(path, mode, stream)) + return NULL; + + fd= _fileno(stream); + } + + if ((osfh= CreateFile(path, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE | + FILE_SHARE_DELETE, NULL, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, + NULL)) == INVALID_HANDLE_VALUE) + return NULL; + + if ((handle_fd= _open_osfhandle((intptr_t)osfh, + _O_APPEND | _O_TEXT)) == -1) + { + CloseHandle(osfh); + return NULL; + } + + if (_dup2(handle_fd, fd) < 0) + { + CloseHandle(osfh); + return NULL; + } + + _close(handle_fd); + + return stream; +} + +#elif defined(__FreeBSD__) + +/* No close operation hook. */ + +static int no_close(void *cookie __attribute__((unused))) +{ + return 0; +} + +/* + A hack around a race condition in the implementation of freopen. + + The race condition steams from the fact that the current fd of + the stream is closed before its number is used to duplicate the + new file descriptor. This defeats the desired atomicity of the + close and duplicate of dup2(). + + See PR number 79887 for reference: + http://www.freebsd.org/cgi/query-pr.cgi?pr=79887 +*/ + +static FILE *my_freebsd_freopen(const char *path, const char *mode, FILE *stream) +{ + int old_fd; + FILE *result; + + flockfile(stream); + + old_fd= fileno(stream); + + /* Use a no operation close hook to avoid having the fd closed. */ + stream->_close= no_close; + + /* Relies on the implicit dup2 to close old_fd. */ + result= freopen(path, mode, stream); + + /* If successful, the _close hook was replaced. */ + + if (result == NULL) + close(old_fd); + else + funlockfile(result); + + return result; +} + +#endif + + +/** + Change the file associated with a file stream. + + @param path Path to file. + @param mode Mode of the stream. + @param stream File stream. + + @note + This function is used to redirect stdout and stderr to a file and + subsequently to close and reopen that file for log rotation. + + @retval A FILE pointer on success. Otherwise, NULL. +*/ + +FILE *my_freopen(const char *path, const char *mode, FILE *stream) +{ + FILE *result; + +#if defined(_WIN32) + result= my_win_freopen(path, mode, stream); +#elif defined(__FreeBSD__) + /* + XXX: Once the fix is ported to the stable releases, this should + be dependent upon the specific FreeBSD versions. Check at: + http://www.freebsd.org/cgi/query-pr.cgi?pr=79887 + */ + if (getosreldate() > 900027) + result= freopen(path, mode, stream); + else + result= my_freebsd_freopen(path, mode, stream); +#else + result= freopen(path, mode, stream); +#endif + + return result; +} + /* Close a stream */ int my_fclose(FILE *fd, myf MyFlags) diff --git a/mysys/my_fstream.c b/mysys/my_fstream.c index 0c7e4ef7aa3..83cb0d261c0 100644 --- a/mysys/my_fstream.c +++ b/mysys/my_fstream.c @@ -124,10 +124,9 @@ size_t my_fwrite(FILE *stream, const uchar *Buffer, size_t Count, myf MyFlags) } #endif #if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM) -#ifdef THREAD if (my_thread_var->abort) MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ -#endif + if ((errno == ENOSPC || errno == EDQUOT) && (MyFlags & MY_WAIT_IF_FULL)) { diff --git a/mysys/my_gethostbyname.c b/mysys/my_gethostbyname.c index 8a9c721c2fb..28ecec13ef2 100644 --- a/mysys/my_gethostbyname.c +++ b/mysys/my_gethostbyname.c @@ -78,9 +78,7 @@ struct hostent *my_gethostbyname_r(const char *name, #else /* !HAVE_GETHOSTBYNAME_R */ -#ifdef THREAD extern mysql_mutex_t LOCK_gethostbyname_r; -#endif /* No gethostbyname_r() function exists. diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 5e66d2fc189..51c45ff1309 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -602,6 +602,24 @@ static char *check_struct_option(char *cur_arg, char *key_name) } } +/** + Parse a boolean command line argument + + "ON", "TRUE" and "1" will return true, + other values will return false. + + @param[in] argument The value argument + @return boolean value +*/ +static my_bool get_bool_argument(const char *argument) +{ + if (!my_strcasecmp(&my_charset_latin1, argument, "true") || + !my_strcasecmp(&my_charset_latin1, argument, "on")) + return 1; + else + return (my_bool) atoi(argument); +} + /* function: setval @@ -629,7 +647,7 @@ static int setval(const struct my_option *opts, void *value, char *argument, switch ((opts->var_type & GET_TYPE_MASK)) { case GET_BOOL: /* If argument differs from 0, enable option, else disable */ - *((my_bool*) value)= (my_bool) atoi(argument) != 0; + *((my_bool*) value)= get_bool_argument(argument); break; case GET_INT: *((int*) value)= (int) getopt_ll(argument, opts, &err); diff --git a/mysys/my_getsystime.c b/mysys/my_getsystime.c index cc5d1b83efb..614f49fc425 100644 --- a/mysys/my_getsystime.c +++ b/mysys/my_getsystime.c @@ -165,7 +165,13 @@ ulonglong my_micro_time_and_time(time_t *time_arg) mysql_mutex_lock(&THR_LOCK_time); cur_gethrtime= gethrtime(); - if ((cur_gethrtime - prev_gethrtime) > DELTA_FOR_SECONDS) + /* + Due to bugs in the Solaris (x86) implementation of gethrtime(), + the time returned by it might not be monotonic. Don't use the + cached time(2) value if this is a case. + */ + if ((prev_gethrtime > cur_gethrtime) || + ((cur_gethrtime - prev_gethrtime) > DELTA_FOR_SECONDS)) { cur_time= time(0); prev_gethrtime= cur_gethrtime; diff --git a/mysys/my_init.c b/mysys/my_init.c index ab6ffef7ac7..f5a2d9ac4bd 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -91,23 +91,22 @@ my_bool my_basic_init(void) instrumented_stdin.m_psi= NULL; /* not yet instrumented */ mysql_stdin= & instrumented_stdin; -#if defined(THREAD) if (my_thread_global_init()) return 1; -# if defined(SAFE_MUTEX) + +#if defined(SAFE_MUTEX) safe_mutex_global_init(); /* Must be called early */ -# endif #endif -#if defined(THREAD) && defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) + +#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) fastmutex_global_init(); /* Must be called early */ #endif -#ifdef THREAD + #if defined(HAVE_PTHREAD_INIT) pthread_init(); /* Must be called before DBUG_ENTER */ #endif if (my_thread_basic_global_init()) return 1; -#endif /* $HOME is needed early to parse configuration files located in ~/ */ if ((home_dir= getenv("HOME")) != 0) @@ -138,10 +137,9 @@ my_bool my_init(void) if (my_basic_init()) return 1; -#ifdef THREAD if (my_thread_global_init()) return 1; -#endif /* THREAD */ + { DBUG_ENTER("my_init"); DBUG_PROCESS((char*) (my_progname ? my_progname : "unknown")); @@ -240,7 +238,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", { DBUG_END(); /* Must be done before my_thread_end */ } -#ifdef THREAD + my_thread_end(); my_thread_global_end(); #if defined(SAFE_MUTEX) @@ -251,7 +249,6 @@ Voluntary context switches %ld, Involuntary context switches %ld\n", safe_mutex_end((infoflag & (MY_GIVE_INFO | MY_CHECK_ERROR)) ? stderr : (FILE *) 0); #endif /* defined(SAFE_MUTEX) */ -#endif /* THREAD */ #ifdef __WIN__ if (have_tcpip) @@ -518,7 +515,7 @@ PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock, static PSI_mutex_info all_mysys_mutexes[]= { -#if defined(THREAD) && !defined(HAVE_PREAD) && !defined(_WIN32) +#if !defined(HAVE_PREAD) && !defined(_WIN32) { &key_my_file_info_mutex, "st_my_file_info:mutex", 0}, #endif /* !defined(HAVE_PREAD) && !defined(_WIN32) */ #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) diff --git a/mysys/my_lib.c b/mysys/my_lib.c index 890ff0b5dd1..06f9521a664 100644 --- a/mysys/my_lib.c +++ b/mysys/my_lib.c @@ -41,7 +41,7 @@ # endif #endif -#if defined(THREAD) && defined(HAVE_READDIR_R) +#if defined(HAVE_READDIR_R) #define READDIR(A,B,C) ((errno=readdir_r(A,B,&C)) != 0 || !C) #else #define READDIR(A,B,C) (!(C=readdir(A))) @@ -97,13 +97,12 @@ MY_DIR *my_dir(const char *path, myf MyFlags) DIR *dirp; struct dirent *dp; char tmp_path[FN_REFLEN+1],*tmp_file; -#ifdef THREAD char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1]; -#endif + DBUG_ENTER("my_dir"); DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags)); -#if defined(THREAD) && !defined(HAVE_READDIR_R) +#if !defined(HAVE_READDIR_R) mysql_mutex_lock(&THR_LOCK_open); #endif @@ -135,11 +134,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) tmp_file=strend(tmp_path); -#ifdef THREAD dp= (struct dirent*) dirent_tmp; -#else - dp=0; -#endif while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp))) { @@ -166,7 +161,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) } (void) closedir(dirp); -#if defined(THREAD) && !defined(HAVE_READDIR_R) +#if !defined(HAVE_READDIR_R) mysql_mutex_unlock(&THR_LOCK_open); #endif result->dir_entry= (FILEINFO *)dir_entries_storage->buffer; @@ -178,7 +173,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) DBUG_RETURN(result); error: -#if defined(THREAD) && !defined(HAVE_READDIR_R) +#if !defined(HAVE_READDIR_R) mysql_mutex_unlock(&THR_LOCK_open); #endif my_errno=errno; diff --git a/mysys/my_open.c b/mysys/my_open.c index 8f34ce1c6dc..2aef97b3e34 100644 --- a/mysys/my_open.c +++ b/mysys/my_open.c @@ -89,7 +89,7 @@ int my_close(File fd, myf MyFlags) if ((uint) fd < my_file_limit && my_file_info[fd].type != UNOPEN) { my_free(my_file_info[fd].name); -#if defined(THREAD) && !defined(HAVE_PREAD) && !defined(_WIN32) +#if !defined(HAVE_PREAD) && !defined(_WIN32) mysql_mutex_destroy(&my_file_info[fd].mutex); #endif my_file_info[fd].type = UNOPEN; @@ -125,7 +125,7 @@ File my_register_filename(File fd, const char *FileName, enum file_type { if ((uint) fd >= my_file_limit) { -#if defined(THREAD) && !defined(HAVE_PREAD) +#if !defined(HAVE_PREAD) my_errno= EMFILE; #else thread_safe_increment(my_file_opened,&THR_LOCK_open); @@ -140,7 +140,7 @@ File my_register_filename(File fd, const char *FileName, enum file_type my_file_opened++; my_file_total_opened++; my_file_info[fd].type = type_of_file; -#if defined(THREAD) && !defined(HAVE_PREAD) && !defined(_WIN32) +#if !defined(HAVE_PREAD) && !defined(_WIN32) mysql_mutex_init(key_my_file_info_mutex, &my_file_info[fd].mutex, MY_MUTEX_INIT_FAST); #endif diff --git a/mysys/my_pread.c b/mysys/my_pread.c index d0a0ddaec66..e006360c11b 100644 --- a/mysys/my_pread.c +++ b/mysys/my_pread.c @@ -85,14 +85,14 @@ size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset, DBUG_PRINT("warning",("Read only %d bytes off %u from %d, errno: %d", (int) readbytes, (uint) Count,Filedes,my_errno)); -#ifdef THREAD + if ((readbytes == 0 || readbytes == (size_t) -1) && errno == EINTR) { DBUG_PRINT("debug", ("my_pread() was interrupted and returned %d", (int) readbytes)); continue; /* Interrupted */ } -#endif + if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { if (readbytes == (size_t) -1) @@ -173,10 +173,10 @@ size_t my_pwrite(File Filedes, const uchar *Buffer, size_t Count, } DBUG_PRINT("error",("Write only %u bytes", (uint) writtenbytes)); #ifndef NO_BACKGROUND -#ifdef THREAD + if (my_thread_var->abort) MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ -#endif + if ((my_errno == ENOSPC || my_errno == EDQUOT) && (MyFlags & MY_WAIT_IF_FULL)) { diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index dee34d10b38..150bde3fb33 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -18,7 +18,6 @@ #define DONT_REMAP_PTHREAD_FUNCTIONS #include "mysys_priv.h" -#ifdef THREAD #include <signal.h> #include <m_string.h> #include <thr_alarm.h> @@ -468,4 +467,3 @@ int pthread_dummy(int ret) { return ret; } -#endif /* THREAD */ diff --git a/mysys/my_read.c b/mysys/my_read.c index 75f9dd64f1d..dbe9006a1d3 100644 --- a/mysys/my_read.c +++ b/mysys/my_read.c @@ -59,14 +59,14 @@ size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags) DBUG_PRINT("warning",("Read only %d bytes off %lu from %d, errno: %d", (int) readbytes, (ulong) Count, Filedes, my_errno)); -#ifdef THREAD + if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR) { DBUG_PRINT("debug", ("my_read() was interrupted and returned %ld", (long) readbytes)); continue; /* Interrupted */ } -#endif + if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { if (readbytes == (size_t) -1) diff --git a/mysys/my_static.c b/mysys/my_static.c index d7354555f3d..ec8d66ab0cf 100644 --- a/mysys/my_static.c +++ b/mysys/my_static.c @@ -32,9 +32,7 @@ char curr_dir[FN_REFLEN]= {0}, ulong my_stream_opened=0,my_file_opened=0, my_tmp_file_created=0; ulong my_file_total_opened= 0; int my_umask=0664, my_umask_dir=0777; -#ifndef THREAD -int my_errno=0; -#endif + struct st_my_file_info my_file_info_default[MY_NFILE]; uint my_file_limit= MY_NFILE; struct st_my_file_info *my_file_info= my_file_info_default; diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 045b56b11c2..c4b56cde850 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -22,7 +22,6 @@ #include <m_string.h> #include <signal.h> -#ifdef THREAD pthread_key(struct st_my_thread_var*, THR_KEY_mysys); mysql_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_myisam, THR_LOCK_heap, @@ -532,4 +531,3 @@ static void install_sigabrt_handler(void) } #endif -#endif /* THREAD */ diff --git a/mysys/my_write.c b/mysys/my_write.c index 3eac1364f46..64f7546620f 100644 --- a/mysys/my_write.c +++ b/mysys/my_write.c @@ -52,10 +52,9 @@ size_t my_write(File Filedes, const uchar *Buffer, size_t Count, myf MyFlags) DBUG_PRINT("error",("Write only %ld bytes, error: %d", (long) writtenbytes, my_errno)); #ifndef NO_BACKGROUND -#ifdef THREAD if (my_thread_var->abort) MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ -#endif + if ((my_errno == ENOSPC || my_errno == EDQUOT) && (MyFlags & MY_WAIT_IF_FULL)) { diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h index 1ae6a9e3a99..4e642b7e3d3 100644 --- a/mysys/mysys_priv.h +++ b/mysys/mysys_priv.h @@ -24,7 +24,6 @@ #include <sys/resource.h> #endif -#ifdef THREAD #include <my_pthread.h> #ifdef HAVE_PSI_INTERFACE @@ -62,9 +61,6 @@ extern PSI_thread_key key_thread_alarm; extern mysql_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache; extern mysql_mutex_t THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_net; extern mysql_mutex_t THR_LOCK_charset, THR_LOCK_time; -#else /* THREAD */ -#include <my_no_pthread.h> -#endif /* THREAD */ #include <mysql/psi/mysql_file.h> diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index 54eef693558..2e427f96bdd 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -18,7 +18,7 @@ #include "mysys_priv.h" #include <my_global.h> -#if defined(THREAD) && !defined(DONT_USE_THR_ALARM) +#if !defined(DONT_USE_THR_ALARM) #include <errno.h> #include <my_pthread.h> #include <signal.h> @@ -686,15 +686,14 @@ void resize_thr_alarm(uint max_alarms) #endif /* __WIN__ */ -#endif /* THREAD */ - +#endif /**************************************************************************** Handling of test case (when compiled with -DMAIN) ***************************************************************************/ #ifdef MAIN -#if defined(THREAD) && !defined(DONT_USE_THR_ALARM) +#if !defined(DONT_USE_THR_ALARM) static mysql_cond_t COND_thread_count; static mysql_mutex_t LOCK_thread_count; @@ -961,17 +960,13 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) return 0; } -#else /* THREAD */ +#else /* !defined(DONT_USE_ALARM_THREAD) */ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) { -#ifndef THREAD - printf("thr_alarm disabled because we are not using threads\n"); -#else printf("thr_alarm disabled with DONT_USE_THR_ALARM\n"); -#endif exit(1); } -#endif /* THREAD */ +#endif /* !defined(DONT_USE_ALARM_THREAD) */ #endif /* MAIN */ diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c index d96d08ea0c3..2ab283e068d 100644 --- a/mysys/thr_lock.c +++ b/mysys/thr_lock.c @@ -74,7 +74,6 @@ one TL_WRITE_DELAYED lock at the same time as multiple read locks. #include "mysys_priv.h" -#ifdef THREAD #include "thr_lock.h" #include <m_string.h> #include <errno.h> @@ -1451,7 +1450,6 @@ void thr_print_locks(void) mysql_mutex_unlock(&THR_LOCK_lock); } -#endif /* THREAD */ /***************************************************************************** ** Test of thread locks @@ -1459,8 +1457,6 @@ void thr_print_locks(void) #ifdef MAIN -#ifdef THREAD - struct st_test { uint lock_nr; enum thr_lock_type lock_type; @@ -1689,13 +1685,4 @@ int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) return 0; } -#else /* THREAD */ - -int main(int argc __attribute__((unused)),char **argv __attribute__((unused))) -{ - printf("thr_lock disabled because we are not using threads\n"); - exit(1); -} - -#endif /* THREAD */ #endif /* MAIN */ diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c index 00890bc0425..37ced4f7633 100644 --- a/mysys/thr_mutex.c +++ b/mysys/thr_mutex.c @@ -19,7 +19,7 @@ #if defined(TARGET_OS_LINUX) && !defined (__USE_UNIX98) #define __USE_UNIX98 /* To get rw locks under Linux */ #endif -#if defined(THREAD) && defined(SAFE_MUTEX) +#if defined(SAFE_MUTEX) #undef SAFE_MUTEX /* Avoid safe_mutex redefinitions */ #include "mysys_priv.h" #include "my_static.h" @@ -395,9 +395,9 @@ void safe_mutex_end(FILE *file __attribute__((unused))) #endif /* SAFE_MUTEX_DETECT_DESTROY */ } -#endif /* THREAD && SAFE_MUTEX */ +#endif /* SAFE_MUTEX */ -#if defined(THREAD) && defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) +#if defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) #include "mysys_priv.h" #include "my_static.h" @@ -500,4 +500,4 @@ void fastmutex_global_init(void) #endif } -#endif /* defined(THREAD) && defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) */ +#endif /* defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) */ diff --git a/mysys/thr_rwlock.c b/mysys/thr_rwlock.c index 13651221d37..bad80b43eef 100644 --- a/mysys/thr_rwlock.c +++ b/mysys/thr_rwlock.c @@ -16,7 +16,6 @@ /* Synchronization - readers / writer thread locks */ #include "mysys_priv.h" -#if defined(THREAD) #if defined(NEED_MY_RW_LOCK) #include <errno.h> @@ -471,4 +470,3 @@ int rw_pr_unlock(rw_pr_lock_t *rwlock) } -#endif /* defined(THREAD) */ |