summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorunknown <monty@hundin.mysql.fi>2002-04-02 17:54:57 +0300
committerunknown <monty@hundin.mysql.fi>2002-04-02 17:54:57 +0300
commit1f070c3febada035d041420c527bdf30c407ad13 (patch)
tree0918e7f417ac64ab19af6ea441c12c97e897c1b9 /mysys
parent0681ab1ef952e8186e5ddd442f312e2641be6484 (diff)
downloadmariadb-git-1f070c3febada035d041420c527bdf30c407ad13.tar.gz
Cleanups
Don't use DBUG library for struct st_my_thread_var to make code less complicated. Docs/manual.texi: Cleanup acinclude.m4: Search after openssl in /usr/local client/mysql.cc: Fix prompt client/mysqladmin.c: Cleanup client/mysqltest.c: Cleanup include/my_pthread.h: Move thread variables to the right location include/my_sys.h: Move thread variables to the right location include/mysql.h: Clean up client prototypes libmysql/libmysql.c: Clean up client prototypes mysys/my_static.h: Cleanup mysys/my_thr_init.c: Don't use DBUG library for struct st_my_thread_var to make code less complicated sql/item_cmpfunc.cc: Small optimization sql/net_pkg.cc: Cleanup sql/sql_parse.cc: Allow VARCHAR(0)
Diffstat (limited to 'mysys')
-rw-r--r--mysys/my_static.h7
-rw-r--r--mysys/my_thr_init.c47
2 files changed, 19 insertions, 35 deletions
diff --git a/mysys/my_static.h b/mysys/my_static.h
index ca384009063..88faf24ce82 100644
--- a/mysys/my_static.h
+++ b/mysys/my_static.h
@@ -57,10 +57,11 @@ extern const char *soundex_map;
extern USED_MEM* my_once_root_block;
extern uint my_once_extra;
-/* these threads are exept from safemalloc leak scrutiny unless
- PEDANTIC_SAFEMALLOC is defined
+/*
+ These threads are exept from safemalloc leak scrutiny unless
+ PEDANTIC_SAFEMALLOC is defined
*/
-extern pthread_t signal_thread,kill_thread;
+extern pthread_t signal_thread, kill_thread;
#ifndef HAVE_TEMPNAM
extern int _my_tempnam_used;
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index 2c7fd098c63..5b137df20f8 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -111,6 +111,7 @@ my_bool my_thread_init(void)
#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
pthread_mutex_lock(&THR_LOCK_lock);
#endif
+
#if !defined(__WIN__) || defined(USE_TLS)
if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys))
{
@@ -121,17 +122,8 @@ my_bool my_thread_init(void)
pthread_mutex_unlock(&THR_LOCK_lock);
return 0; /* Safequard */
}
- /* We must have many calloc() here because these are freed on
- pthread_exit */
- /*
- Sasha: the above comment does not make sense. I have changed calloc() to
- equivalent my_malloc() but it was calloc() before. It seems like the
- comment is out of date - we always call my_thread_end() before
- pthread_exit() to clean up. Note that I have also fixed up DBUG
- code to be able to call it from my_thread_init()
- */
if (!(tmp=(struct st_my_thread_var *)
- my_malloc(sizeof(struct st_my_thread_var),MYF(MY_WME|MY_ZEROFILL))))
+ calloc(1, sizeof(struct st_my_thread_var))))
{
pthread_mutex_unlock(&THR_LOCK_lock);
return 1;
@@ -139,21 +131,18 @@ my_bool my_thread_init(void)
pthread_setspecific(THR_KEY_mysys,tmp);
#else
- /* Sasha: TODO - explain what exactly we are doing on Windows
- At first glance, I have a hard time following the code
- */
- if (THR_KEY_mysys.id) /* Already initialized */
- {
-#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
- pthread_mutex_unlock(&THR_LOCK_lock);
-#endif
- return 0;
- }
+ /*
+ Skip initialization if the thread specific variable is already initialized
+ */
+ if (THR_KEY_mysys.id)
+ goto end;
tmp= &THR_KEY_mysys;
#endif
tmp->id= ++thread_id;
pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST);
pthread_cond_init(&tmp->suspend, NULL);
+
+end:
#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
pthread_mutex_unlock(&THR_LOCK_lock);
#endif
@@ -170,11 +159,7 @@ void my_thread_end(void)
if (tmp)
{
#if !defined(DBUG_OFF)
- /* Sasha: tmp->dbug is allocated inside DBUG library
- so for now we will not mess with trying to use my_malloc()/
- my_free(), but in the future it would be nice to figure out a
- way to do it
- */
+ /* tmp->dbug is allocated inside DBUG library */
if (tmp->dbug)
{
free(tmp->dbug);
@@ -186,15 +171,13 @@ void my_thread_end(void)
#endif
pthread_mutex_destroy(&tmp->mutex);
#if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS)
- /* we need to setspecific to 0 BEFORE we call my_free, as my_free
- uses some DBUG_ macros that will use the follow the specific
- pointer after the block it is pointing to has been freed if
- specific does not get reset first
- */
- pthread_setspecific(THR_KEY_mysys,0);
- my_free((gptr)tmp,MYF(MY_WME));
+ free(tmp);
#endif
}
+ /* The following free has to be done, even if my_thread_var() is 0 */
+#if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS)
+ pthread_setspecific(THR_KEY_mysys,0);
+#endif
}
struct st_my_thread_var *_my_thread_var(void)