mirror of
https://github.com/MariaDB/server.git
synced 2026-05-14 19:07:15 +02:00
Merge from mysql-next-mr.
This commit is contained in:
commit
01b455d84e
50 changed files with 434 additions and 446 deletions
|
|
@ -13,8 +13,6 @@
|
|||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
|
||||
|
||||
# Only the server link with this library, the client libraries and the client
|
||||
# executables all link with recompiles of source found in the "mysys" directory.
|
||||
# So we only need to create one version of this library, with the "static"
|
||||
|
|
|
|||
|
|
@ -248,6 +248,7 @@ static int add_collation(CHARSET_INFO *cs)
|
|||
{
|
||||
#if defined(HAVE_CHARSET_ucs2) && defined(HAVE_UCA_COLLATIONS)
|
||||
copy_uca_collation(newcs, &my_charset_ucs2_unicode_ci);
|
||||
newcs->state|= MY_CS_AVAILABLE | MY_CS_LOADED | MY_CS_NONASCII;
|
||||
#endif
|
||||
}
|
||||
else if (!strcmp(cs->csname, "utf8"))
|
||||
|
|
@ -280,6 +281,8 @@ static int add_collation(CHARSET_INFO *cs)
|
|||
|
||||
if (my_charset_is_8bit_pure_ascii(all_charsets[cs->number]))
|
||||
all_charsets[cs->number]->state|= MY_CS_PUREASCII;
|
||||
if (!my_charset_is_ascii_compatible(cs))
|
||||
all_charsets[cs->number]->state|= MY_CS_NONASCII;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ int my_delete(const char *name, myf MyFlags)
|
|||
DBUG_RETURN(err);
|
||||
} /* my_delete */
|
||||
|
||||
#if defined(__WIN__) && defined(__NT__)
|
||||
#if defined(__WIN__)
|
||||
/*
|
||||
Delete file which is possibly not closed.
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@
|
|||
#ifdef _MSC_VER
|
||||
#include <locale.h>
|
||||
#include <crtdbg.h>
|
||||
/* WSAStartup needs winsock library*/
|
||||
#pragma comment(lib, "ws2_32")
|
||||
#endif
|
||||
my_bool have_tcpip=0;
|
||||
static void my_win_init(void);
|
||||
|
|
|
|||
|
|
@ -23,11 +23,7 @@
|
|||
#include <signal.h>
|
||||
|
||||
#ifdef THREAD
|
||||
#ifdef USE_TLS
|
||||
pthread_key(struct st_my_thread_var*, THR_KEY_mysys);
|
||||
#else
|
||||
pthread_key(struct st_my_thread_var, THR_KEY_mysys);
|
||||
#endif /* USE_TLS */
|
||||
pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,
|
||||
THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap,
|
||||
THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads, THR_LOCK_time;
|
||||
|
|
@ -46,7 +42,9 @@ pthread_mutexattr_t my_fast_mutexattr;
|
|||
#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
|
||||
pthread_mutexattr_t my_errorcheck_mutexattr;
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static void install_sigabrt_handler();
|
||||
#endif
|
||||
#ifdef TARGET_OS_LINUX
|
||||
|
||||
/*
|
||||
|
|
@ -149,15 +147,18 @@ my_bool my_thread_global_init(void)
|
|||
pthread_mutex_init(&THR_LOCK_threads,MY_MUTEX_INIT_FAST);
|
||||
pthread_mutex_init(&THR_LOCK_time,MY_MUTEX_INIT_FAST);
|
||||
pthread_cond_init(&THR_COND_threads, NULL);
|
||||
#if defined( __WIN__) || defined(OS2)
|
||||
win_pthread_init();
|
||||
#endif
|
||||
|
||||
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
|
||||
pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW);
|
||||
#endif
|
||||
#ifndef HAVE_GETHOSTBYNAME_R
|
||||
pthread_mutex_init(&LOCK_gethostbyname_r,MY_MUTEX_INIT_SLOW);
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
install_sigabrt_handler();
|
||||
#endif
|
||||
|
||||
if (my_thread_init())
|
||||
{
|
||||
my_thread_global_end(); /* Clean up */
|
||||
|
|
@ -258,7 +259,6 @@ my_bool my_thread_init(void)
|
|||
(ulong) pthread_self());
|
||||
#endif
|
||||
|
||||
#if !defined(__WIN__) || defined(USE_TLS)
|
||||
if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys))
|
||||
{
|
||||
#ifdef EXTRA_DEBUG_THREADS
|
||||
|
|
@ -267,26 +267,18 @@ my_bool my_thread_init(void)
|
|||
#endif
|
||||
goto end;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
install_sigabrt_handler();
|
||||
#endif
|
||||
|
||||
if (!(tmp= (struct st_my_thread_var *) calloc(1, sizeof(*tmp))))
|
||||
{
|
||||
error= 1;
|
||||
goto end;
|
||||
}
|
||||
pthread_setspecific(THR_KEY_mysys,tmp);
|
||||
|
||||
#else /* defined(__WIN__) && !(defined(USE_TLS) */
|
||||
/*
|
||||
Skip initialization if the thread specific variable is already initialized
|
||||
*/
|
||||
if (THR_KEY_mysys.id)
|
||||
goto end;
|
||||
tmp= &THR_KEY_mysys;
|
||||
#endif
|
||||
#if defined(__WIN__) && defined(EMBEDDED_LIBRARY)
|
||||
tmp->pthread_self= (pthread_t) getpid();
|
||||
#else
|
||||
tmp->pthread_self= pthread_self();
|
||||
#endif
|
||||
pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST);
|
||||
pthread_cond_init(&tmp->suspend, NULL);
|
||||
tmp->init= 1;
|
||||
|
|
@ -342,11 +334,7 @@ void my_thread_end(void)
|
|||
pthread_cond_destroy(&tmp->suspend);
|
||||
#endif
|
||||
pthread_mutex_destroy(&tmp->mutex);
|
||||
#if !defined(__WIN__) || defined(USE_TLS)
|
||||
free(tmp);
|
||||
#else
|
||||
tmp->init= 0;
|
||||
#endif
|
||||
|
||||
/*
|
||||
Decrement counter for number of running threads. We are using this
|
||||
|
|
@ -360,10 +348,7 @@ void my_thread_end(void)
|
|||
pthread_cond_signal(&THR_COND_threads);
|
||||
pthread_mutex_unlock(&THR_LOCK_threads);
|
||||
}
|
||||
/* The following free has to be done, even if my_thread_var() is 0 */
|
||||
#if !defined(__WIN__) || defined(USE_TLS)
|
||||
pthread_setspecific(THR_KEY_mysys,0);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct st_my_thread_var *_my_thread_var(void)
|
||||
|
|
@ -419,4 +404,30 @@ static uint get_thread_lib(void)
|
|||
return THD_LIB_OTHER;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
/*
|
||||
In Visual Studio 2005 and later, default SIGABRT handler will overwrite
|
||||
any unhandled exception filter set by the application and will try to
|
||||
call JIT debugger. This is not what we want, this we calling __debugbreak
|
||||
to stop in debugger, if process is being debugged or to generate
|
||||
EXCEPTION_BREAKPOINT and then handle_segfault will do its magic.
|
||||
*/
|
||||
|
||||
#if (_MSC_VER >= 1400)
|
||||
static void my_sigabrt_handler(int sig)
|
||||
{
|
||||
__debugbreak();
|
||||
}
|
||||
#endif /*_MSC_VER >=1400 */
|
||||
|
||||
static void install_sigabrt_handler(void)
|
||||
{
|
||||
#if (_MSC_VER >=1400)
|
||||
/*abort() should not override our exception filter*/
|
||||
_set_abort_behavior(0,_CALL_REPORTFAULT);
|
||||
signal(SIGABRT,my_sigabrt_handler);
|
||||
#endif /* _MSC_VER >=1400 */
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* THREAD */
|
||||
|
|
|
|||
|
|
@ -16,12 +16,11 @@
|
|||
/*****************************************************************************
|
||||
** The following is a simple implementation of posix conditions
|
||||
*****************************************************************************/
|
||||
#if defined(_WIN32)
|
||||
|
||||
#undef SAFE_MUTEX /* Avoid safe_mutex redefinitions */
|
||||
#include "mysys_priv.h"
|
||||
#if defined(THREAD) && defined(__WIN__)
|
||||
#include <m_string.h>
|
||||
#undef getpid
|
||||
#include <process.h>
|
||||
#include <sys/timeb.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -314,10 +314,10 @@ size_t my_win_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset)
|
|||
if(!ReadFile(hFile, Buffer, (DWORD)Count, &nBytesRead, &ov))
|
||||
{
|
||||
DWORD lastError= GetLastError();
|
||||
/*
|
||||
ERROR_BROKEN_PIPE is returned when no more data coming
|
||||
through e.g. a command pipe in windows : see MSDN on ReadFile.
|
||||
*/
|
||||
/*
|
||||
ERROR_BROKEN_PIPE is returned when no more data coming
|
||||
through e.g. a command pipe in windows : see MSDN on ReadFile.
|
||||
*/
|
||||
if(lastError == ERROR_HANDLE_EOF || lastError == ERROR_BROKEN_PIPE)
|
||||
DBUG_RETURN(0); /*return 0 at EOF*/
|
||||
my_osmaperr(lastError);
|
||||
|
|
@ -367,8 +367,8 @@ size_t my_win_pwrite(File Filedes, const uchar *Buffer, size_t Count,
|
|||
LARGE_INTEGER li;
|
||||
|
||||
DBUG_ENTER("my_win_pwrite");
|
||||
DBUG_PRINT("my",("Filedes: %d, Buffer: %p, Count: %zd, offset: %llu",
|
||||
Filedes, Buffer, Count, (ulonglong)offset));
|
||||
DBUG_PRINT("my",("Filedes: %d, Buffer: %p, Count: %llu, offset: %llu",
|
||||
Filedes, Buffer, (ulonglong)Count, (ulonglong)offset));
|
||||
|
||||
if(!Count)
|
||||
DBUG_RETURN(0);
|
||||
|
|
@ -425,7 +425,8 @@ size_t my_win_write(File fd, const uchar *Buffer, size_t Count)
|
|||
HANDLE hFile;
|
||||
|
||||
DBUG_ENTER("my_win_write");
|
||||
DBUG_PRINT("my",("Filedes: %d, Buffer: %p, Count %zd", fd, Buffer, Count));
|
||||
DBUG_PRINT("my",("Filedes: %d, Buffer: %p, Count %llu", fd, Buffer,
|
||||
(ulonglong)Count));
|
||||
if(my_get_open_flags(fd) & _O_APPEND)
|
||||
{
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -14,33 +14,23 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
||||
|
||||
/*****************************************************************************
|
||||
** Simulation of posix threads calls for WIN95 and NT
|
||||
** Simulation of posix threads calls for Windows
|
||||
*****************************************************************************/
|
||||
|
||||
#if defined (_WIN32)
|
||||
/* SAFE_MUTEX will not work until the thread structure is up to date */
|
||||
#undef SAFE_MUTEX
|
||||
|
||||
#include "mysys_priv.h"
|
||||
#if defined(THREAD) && defined(__WIN__)
|
||||
#include <m_string.h>
|
||||
#undef getpid
|
||||
#include <process.h>
|
||||
#include <signal.h>
|
||||
|
||||
static pthread_mutex_t THR_LOCK_thread;
|
||||
static void install_sigabrt_handler(void);
|
||||
|
||||
struct pthread_map
|
||||
struct thread_start_parameter
|
||||
{
|
||||
HANDLE pthreadself;
|
||||
pthread_handler func;
|
||||
void *param;
|
||||
void *arg;
|
||||
};
|
||||
|
||||
void win_pthread_init(void)
|
||||
{
|
||||
pthread_mutex_init(&THR_LOCK_thread,MY_MUTEX_INIT_FAST);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Adapter to @c pthread_mutex_trylock()
|
||||
|
||||
|
|
@ -62,79 +52,81 @@ win_pthread_mutex_trylock(pthread_mutex_t *mutex)
|
|||
return EBUSY;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** We have tried to use '_beginthreadex' instead of '_beginthread' here
|
||||
** but in this case the program leaks about 512 characters for each
|
||||
** created thread !
|
||||
** As we want to save the created thread handler for other threads to
|
||||
** use and to be returned by pthread_self() (instead of the Win32 pseudo
|
||||
** handler), we have to go trough pthread_start() to catch the returned handler
|
||||
** in the new thread.
|
||||
*/
|
||||
|
||||
pthread_handler_t pthread_start(void *param)
|
||||
static unsigned int __stdcall pthread_start(void *p)
|
||||
{
|
||||
pthread_handler func=((struct pthread_map *) param)->func;
|
||||
void *func_param=((struct pthread_map *) param)->param;
|
||||
my_thread_init(); /* Will always succeed in windows */
|
||||
pthread_mutex_lock(&THR_LOCK_thread); /* Wait for beginthread to return */
|
||||
win_pthread_self=((struct pthread_map *) param)->pthreadself;
|
||||
pthread_mutex_unlock(&THR_LOCK_thread);
|
||||
free((char*) param); /* Free param from create */
|
||||
pthread_exit((void*) (*func)(func_param));
|
||||
return 0; /* Safety */
|
||||
struct thread_start_parameter *par= (struct thread_start_parameter *)p;
|
||||
pthread_handler func= par->func;
|
||||
void *arg= par->arg;
|
||||
free(p);
|
||||
(*func)(arg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int pthread_create(pthread_t *thread_id, pthread_attr_t *attr,
|
||||
pthread_handler func, void *param)
|
||||
pthread_handler func, void *param)
|
||||
{
|
||||
HANDLE hThread;
|
||||
struct pthread_map *map;
|
||||
uintptr_t handle;
|
||||
struct thread_start_parameter *par;
|
||||
unsigned int stack_size;
|
||||
DBUG_ENTER("pthread_create");
|
||||
|
||||
if (!(map=malloc(sizeof(*map))))
|
||||
DBUG_RETURN(-1);
|
||||
map->func=func;
|
||||
map->param=param;
|
||||
pthread_mutex_lock(&THR_LOCK_thread);
|
||||
#ifdef __BORLANDC__
|
||||
hThread=(HANDLE)_beginthread((void(_USERENTRY *)(void *)) pthread_start,
|
||||
attr->dwStackSize ? attr->dwStackSize :
|
||||
65535, (void*) map);
|
||||
#else
|
||||
hThread=(HANDLE)_beginthread((void( __cdecl *)(void *)) pthread_start,
|
||||
attr->dwStackSize ? attr->dwStackSize :
|
||||
65535, (void*) map);
|
||||
#endif
|
||||
DBUG_PRINT("info", ("hThread=%lu",(long) hThread));
|
||||
*thread_id=map->pthreadself=hThread;
|
||||
pthread_mutex_unlock(&THR_LOCK_thread);
|
||||
par= (struct thread_start_parameter *)malloc(sizeof(*par));
|
||||
if (!par)
|
||||
goto error_return;
|
||||
|
||||
if (hThread == (HANDLE) -1)
|
||||
{
|
||||
int error=errno;
|
||||
DBUG_PRINT("error",
|
||||
("Can't create thread to handle request (error %d)",error));
|
||||
DBUG_RETURN(error ? error : -1);
|
||||
}
|
||||
VOID(SetThreadPriority(hThread, attr->priority)) ;
|
||||
par->func= func;
|
||||
par->arg= param;
|
||||
stack_size= attr?attr->dwStackSize:0;
|
||||
|
||||
handle= _beginthreadex(NULL, stack_size , pthread_start, par, 0, thread_id);
|
||||
if (!handle)
|
||||
goto error_return;
|
||||
DBUG_PRINT("info", ("thread id=%u",*thread_id));
|
||||
|
||||
/* Do not need thread handle, close it */
|
||||
CloseHandle((HANDLE)handle);
|
||||
DBUG_RETURN(0);
|
||||
|
||||
error_return:
|
||||
DBUG_PRINT("error",
|
||||
("Can't create thread to handle request (error %d)",errno));
|
||||
DBUG_RETURN(-1);
|
||||
}
|
||||
|
||||
|
||||
void pthread_exit(void *a)
|
||||
{
|
||||
_endthread();
|
||||
_endthreadex(0);
|
||||
}
|
||||
|
||||
/* This is neaded to get the macro pthread_setspecific to work */
|
||||
|
||||
int win_pthread_setspecific(void *a,void *b,uint length)
|
||||
int pthread_join(pthread_t thread, void **value_ptr)
|
||||
{
|
||||
memcpy(a,b,length);
|
||||
DWORD ret;
|
||||
HANDLE handle;
|
||||
|
||||
handle= OpenThread(SYNCHRONIZE, FALSE, thread);
|
||||
if (!handle)
|
||||
{
|
||||
errno= EINVAL;
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
ret= WaitForSingleObject(handle, INFINITE);
|
||||
|
||||
if(ret != WAIT_OBJECT_0)
|
||||
{
|
||||
errno= EINVAL;
|
||||
goto error_return;
|
||||
}
|
||||
|
||||
CloseHandle(handle);
|
||||
return 0;
|
||||
|
||||
error_return:
|
||||
if(handle)
|
||||
CloseHandle(handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue