summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/hash.c2
-rw-r--r--mysys/my_getopt.c16
-rw-r--r--mysys/my_init.c152
-rw-r--r--mysys/my_thr_init.c35
-rw-r--r--mysys/thr_mutex.c67
5 files changed, 152 insertions, 120 deletions
diff --git a/mysys/hash.c b/mysys/hash.c
index ba606e835a8..63aad7d30ed 100644
--- a/mysys/hash.c
+++ b/mysys/hash.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000 MySQL AB
+/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
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
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 464b1d2e3cc..361f6cb8a90 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -974,24 +974,26 @@ static void init_one_value(const struct my_option *option, uchar* *variable,
*((my_bool*) variable)= (my_bool) value;
break;
case GET_INT:
- *((int*) variable)= (int) value;
+ *((int*) variable)= (int) getopt_ll_limit_value((int) value, option, NULL);
break;
- case GET_UINT: /* Fall through */
case GET_ENUM:
*((uint*) variable)= (uint) value;
break;
+ case GET_UINT:
+ *((uint*) variable)= (uint) getopt_ull_limit_value((uint) value, option, NULL);
+ break;
case GET_LONG:
- *((long*) variable)= (long) value;
+ *((long*) variable)= (long) getopt_ll_limit_value((long) value, option, NULL);
break;
case GET_ULONG:
- *((ulong*) variable)= (ulong) value;
+ *((ulong*) variable)= (ulong) getopt_ull_limit_value((ulong) value, option, NULL);
break;
case GET_LL:
- *((longlong*) variable)= (longlong) value;
+ *((longlong*) variable)= (longlong) getopt_ll_limit_value((longlong) value, option, NULL);
break;
case GET_ULL: /* Fall through */
case GET_SET:
- *((ulonglong*) variable)= (ulonglong) value;
+ *((ulonglong*) variable)= (ulonglong) getopt_ull_limit_value((ulonglong) value, option, NULL);
break;
case GET_DOUBLE:
*((double*) variable)= (double) value;
@@ -1227,7 +1229,7 @@ void my_print_variables(const struct my_option *options)
printf("%d\n", *((int*) value));
break;
case GET_UINT:
- printf("%d\n", *((uint*) value));
+ printf("%u\n", *((uint*) value));
break;
case GET_LONG:
printf("%ld\n", *((long*) value));
diff --git a/mysys/my_init.c b/mysys/my_init.c
index 0c607af5d58..0560d64d9d8 100644
--- a/mysys/my_init.c
+++ b/mysys/my_init.c
@@ -30,7 +30,6 @@
#endif
my_bool have_tcpip=0;
static void my_win_init(void);
-static my_bool win32_have_tcpip(void);
static my_bool win32_init_tcp_ip();
#else
#define my_win_init()
@@ -82,17 +81,15 @@ my_bool my_init(void)
if (my_progname)
my_progname_short= my_progname + dirname_length(my_progname);
-#if defined(THREAD) && defined(SAFE_MUTEX)
- safe_mutex_global_init(); /* Must be called early */
-#endif
-#if defined(THREAD) && defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX)
- fastmutex_global_init(); /* Must be called early */
-#endif
+ /* first initialize systems and global libraries */
netware_init();
#ifdef THREAD
#if defined(HAVE_PTHREAD_INIT)
pthread_init(); /* Must be called before DBUG_ENTER */
#endif
+ /* Initalize our mutex handling */
+ my_mutex_init();
+ /* Initialize mysys global variables and global mutex */
if (my_thread_global_init())
return 1;
#if !defined( __WIN__) && !defined(__NETWARE__)
@@ -226,6 +223,7 @@ Voluntary context switches %ld, Involuntary context switches %ld\n",
#ifdef THREAD
my_thread_end();
my_thread_global_end();
+ my_mutex_end();
#if defined(SAFE_MUTEX)
/*
Check on destroying of mutexes. A few may be left that will get cleaned
@@ -253,29 +251,6 @@ void my_debug_put_break_here(void)
#ifdef __WIN__
-/*
- This code is specially for running MySQL, but it should work in
- other cases too.
-
- Inizializzazione delle variabili d'ambiente per Win a 32 bit.
-
- Vengono inserite nelle variabili d'ambiente (utilizzando cosi'
- le funzioni getenv e putenv) i valori presenti nelle chiavi
- del file di registro:
-
- HKEY_LOCAL_MACHINE\software\MySQL
-
- Se la kiave non esiste nonn inserisce nessun valore
-*/
-
-/* Crea la stringa d'ambiente */
-
-void setEnvString(char *ret, const char *name, const char *value)
-{
- DBUG_ENTER("setEnvString");
- strxmov(ret, name,"=",value,NullS);
- DBUG_VOID_RETURN ;
-}
/*
my_parameter_handler
@@ -325,17 +300,6 @@ int handle_rtc_failure(int err_type, const char *file, int line,
static void my_win_init(void)
{
- HKEY hSoftMysql ;
- DWORD dimName = 256 ;
- DWORD dimData = 1024 ;
- DWORD dimNameValueBuffer = 256 ;
- DWORD dimDataValueBuffer = 1024 ;
- DWORD indexValue = 0 ;
- long retCodeEnumValue ;
- char NameValueBuffer[256] ;
- char DataValueBuffer[1024] ;
- char EnvString[1271] ;
- const char *targetKey = "Software\\MySQL" ;
DBUG_ENTER("my_win_init");
#if defined(_MSC_VER)
@@ -361,6 +325,30 @@ static void my_win_init(void)
_tzset();
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/* The following is used by time functions */
#define OFFSET_TO_EPOC ((__int64) 134774 * 24 * 60 * 60 * 1000 * 1000 * 10)
#define MS 10000000
@@ -385,43 +373,57 @@ static void my_win_init(void)
}
}
- /* apre la chiave HKEY_LOCAL_MACHINES\software\MySQL */
- if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,(LPCTSTR)targetKey,0,
- KEY_READ,&hSoftMysql) != ERROR_SUCCESS)
- DBUG_VOID_RETURN;
-
- /*
- ** Ne legge i valori e li inserisce nell'ambiente
- ** suppone che tutti i valori letti siano di tipo stringa + '\0'
- ** Legge il valore con indice 0 e lo scarta
- */
- retCodeEnumValue = RegEnumValue(hSoftMysql, indexValue++,
- (LPTSTR)NameValueBuffer, &dimNameValueBuffer,
- NULL, NULL, (LPBYTE)DataValueBuffer,
- &dimDataValueBuffer) ;
-
- while (retCodeEnumValue != ERROR_NO_MORE_ITEMS)
{
- char *my_env;
- /* Crea la stringa d'ambiente */
- setEnvString(EnvString, NameValueBuffer, DataValueBuffer) ;
-
- /* Inserisce i dati come variabili d'ambiente */
- my_env=strdup(EnvString); /* variable for putenv must be allocated ! */
- putenv(my_env) ;
-
- dimNameValueBuffer = dimName ;
- dimDataValueBuffer = dimData ;
+ /*
+ Open HKEY_LOCAL_MACHINE\SOFTWARE\MySQL and set any strings found
+ there as environment variables
+ */
+ HKEY key_handle;
+ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCTSTR)"SOFTWARE\\MySQL",
+ 0, KEY_READ, &key_handle) == ERROR_SUCCESS)
+ {
+ LONG ret;
+ DWORD index= 0;
+ DWORD type;
+ char key_name[256], key_data[1024];
+ DWORD key_name_len= sizeof(key_name) - 1;
+ DWORD key_data_len= sizeof(key_data) - 1;
+
+ while ((ret= RegEnumValue(key_handle, index++,
+ key_name, &key_name_len,
+ NULL, &type, (LPBYTE)&key_data,
+ &key_data_len)) != ERROR_NO_MORE_ITEMS)
+ {
+ char env_string[sizeof(key_name) + sizeof(key_data) + 2];
+
+ if (ret == ERROR_MORE_DATA)
+ {
+ /* Registry value larger than 'key_data', skip it */
+ DBUG_PRINT("error", ("Skipped registry value that was too large"));
+ }
+ else if (ret == ERROR_SUCCESS)
+ {
+ if (type == REG_SZ)
+ {
+ strxmov(env_string, key_name, "=", key_data, NullS);
+
+ /* variable for putenv must be allocated ! */
+ putenv(strdup(env_string)) ;
+ }
+ }
+ else
+ {
+ /* Unhandled error, break out of loop */
+ break;
+ }
+
+ key_name_len= sizeof(key_name) - 1;
+ key_data_len= sizeof(key_data) - 1;
+ }
- retCodeEnumValue = RegEnumValue(hSoftMysql, indexValue++,
- NameValueBuffer, &dimNameValueBuffer,
- NULL, NULL, (LPBYTE)DataValueBuffer,
- &dimDataValueBuffer) ;
+ RegCloseKey(key_handle) ;
+ }
}
-
- /* chiude la chiave */
- RegCloseKey(hSoftMysql) ;
-
DBUG_VOID_RETURN ;
}
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index 3f4c4a4d638..252ad9f203e 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -40,12 +40,6 @@ pthread_mutex_t LOCK_localtime_r;
#ifndef HAVE_GETHOSTBYNAME_R
pthread_mutex_t LOCK_gethostbyname_r;
#endif
-#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
-pthread_mutexattr_t my_fast_mutexattr;
-#endif
-#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
-pthread_mutexattr_t my_errorcheck_mutexattr;
-#endif
#ifdef TARGET_OS_LINUX
@@ -124,29 +118,6 @@ my_bool my_thread_global_init(void)
if (my_thread_init())
return 1;
-#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
- /*
- Set mutex type to "fast" a.k.a "adaptive"
-
- In this case the thread may steal the mutex from some other thread
- that is waiting for the same mutex. This will save us some
- context switches but may cause a thread to 'starve forever' while
- waiting for the mutex (not likely if the code within the mutex is
- short).
- */
- pthread_mutexattr_init(&my_fast_mutexattr);
- pthread_mutexattr_settype(&my_fast_mutexattr,
- PTHREAD_MUTEX_ADAPTIVE_NP);
-#endif
-#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
- /*
- Set mutex type to "errorcheck"
- */
- pthread_mutexattr_init(&my_errorcheck_mutexattr);
- pthread_mutexattr_settype(&my_errorcheck_mutexattr,
- PTHREAD_MUTEX_ERRORCHECK);
-#endif
-
/* Mutex uses by mysys */
pthread_mutex_init(&THR_LOCK_open,MY_MUTEX_INIT_FAST);
pthread_mutex_init(&THR_LOCK_lock,MY_MUTEX_INIT_FAST);
@@ -226,12 +197,6 @@ void my_thread_global_end(void)
}
pthread_key_delete(THR_KEY_mysys);
-#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
- pthread_mutexattr_destroy(&my_fast_mutexattr);
-#endif
-#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
- pthread_mutexattr_destroy(&my_errorcheck_mutexattr);
-#endif
if (all_threads_killed)
{
pthread_mutex_destroy(&THR_LOCK_threads);
diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c
index 4f19f5d79c4..cc6bdab2522 100644
--- a/mysys/thr_mutex.c
+++ b/mysys/thr_mutex.c
@@ -19,7 +19,11 @@
#if defined(TARGET_OS_LINUX) && !defined (__USE_UNIX98)
#define __USE_UNIX98 /* To get rw locks under Linux */
#endif
-#if defined(THREAD) && defined(SAFE_MUTEX)
+#ifdef SAFE_MUTEX
+#define SAFE_MUTEX_DEFINED
+#endif
+
+#if defined(THREAD)
#undef SAFE_MUTEX /* Avoid safe_mutex redefinitions */
#include "mysys_priv.h"
#include "my_static.h"
@@ -41,6 +45,13 @@
#endif
#endif /* DO_NOT_REMOVE_THREAD_WRAPPERS */
+#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
+pthread_mutexattr_t my_fast_mutexattr;
+#endif
+#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+pthread_mutexattr_t my_errorcheck_mutexattr;
+#endif
+#ifdef SAFE_MUTEX_DEFINED
static pthread_mutex_t THR_LOCK_mutex;
static ulong safe_mutex_count= 0; /* Number of mutexes created */
static ulong safe_mutex_id= 0;
@@ -60,7 +71,58 @@ static my_bool remove_from_used_mutex(safe_mutex_deadlock_t *locked_mutex,
safe_mutex_t *mutex);
static void print_deadlock_warning(safe_mutex_t *new_mutex,
safe_mutex_t *conflicting_mutex);
+#endif
+
+
+/* Initialize all mutex handling */
+
+void my_mutex_init()
+{
+ /* Initialize mutex attributes */
+#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
+ /*
+ Set mutex type to "fast" a.k.a "adaptive"
+
+ In this case the thread may steal the mutex from some other thread
+ that is waiting for the same mutex. This will save us some
+ context switches but may cause a thread to 'starve forever' while
+ waiting for the mutex (not likely if the code within the mutex is
+ short).
+ */
+ pthread_mutexattr_init(&my_fast_mutexattr);
+ pthread_mutexattr_settype(&my_fast_mutexattr,
+ PTHREAD_MUTEX_ADAPTIVE_NP);
+#endif
+#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+ /*
+ Set mutex type to "errorcheck"
+ */
+ pthread_mutexattr_init(&my_errorcheck_mutexattr);
+ pthread_mutexattr_settype(&my_errorcheck_mutexattr,
+ PTHREAD_MUTEX_ERRORCHECK);
+#endif
+
+#if defined(SAFE_MUTEX_DEFINED)
+ safe_mutex_global_init();
+#elif defined(MY_PTHREAD_FASTMUTEX)
+ fastmutex_global_init();
+#endif
+}
+
+void my_mutex_end()
+{
+#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
+ pthread_mutexattr_destroy(&my_fast_mutexattr);
+#endif
+#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
+ pthread_mutexattr_destroy(&my_errorcheck_mutexattr);
+#endif
+}
+
+
+/* Initialize safe_mutex handling */
+#ifdef SAFE_MUTEX_DEFINED
void safe_mutex_global_init(void)
{
pthread_mutex_init(&THR_LOCK_mutex,MY_MUTEX_INIT_FAST);
@@ -865,4 +927,5 @@ void fastmutex_global_init(void)
#endif
}
-#endif /* defined(THREAD) && defined(MY_PTHREAD_FASTMUTEX) && !defined(SAFE_MUTEX) */
+#endif /* SAFE_MUTEX_DEFINED */
+#endif /* THREAD */