diff options
author | unknown <sasha@mysql.sashanet.com> | 2002-03-26 22:19:23 -0700 |
---|---|---|
committer | unknown <sasha@mysql.sashanet.com> | 2002-03-26 22:19:23 -0700 |
commit | 079a551ca735e79f3d7a2ebbecf8be4d4ba7608a (patch) | |
tree | ab4d73690dcb8e3ef54e70015f1838cf17a2577a /mysys/my_thr_init.c | |
parent | 9c435716a9773f78cd5db0a992bd4b89b83bc25a (diff) | |
download | mariadb-git-079a551ca735e79f3d7a2ebbecf8be4d4ba7608a.tar.gz |
coverted my_thread_init() /end to use my_malloc()/my_free() to help track
down replication corruption
dbug/dbug.c:
fixed DBUG_ macros to not crash if my_thread_init() had not been called
include/my_sys.h:
keep track of shutdown, main, and signal threads for safemalloc
mysys/my_static.h:
keep track of thread in safemalloc blocks
mysys/my_thr_init.c:
use my_malloc()/my_free() in my_thread_init()
mysys/safemalloc.c:
keep track of threads
do not fuss if main,signal, or shutdown thread still has allocated blocks
when we call TERMINATE() as some blocks are freed later and there is no
easy way to make TERMINATE() wait for those threads
sql/mysqld.cc:
keep track of signal, main, and shutdown threads
Diffstat (limited to 'mysys/my_thr_init.c')
-rw-r--r-- | mysys/my_thr_init.c | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index b4d98feeeb6..2c7fd098c63 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -105,19 +105,33 @@ static long thread_id=0; my_bool my_thread_init(void) { struct st_my_thread_var *tmp; +#ifdef EXTRA_DEBUG + fprintf(stderr,"my_thread_init(): thread_id=%ld\n",pthread_self()); +#endif #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)) { +#ifdef EXTRA_DEBUG + fprintf(stderr,"my_thread_init() called more than once in thread %ld\n", + pthread_self()); +#endif 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 *) - calloc(1,sizeof(struct st_my_thread_var)))) + my_malloc(sizeof(struct st_my_thread_var),MYF(MY_WME|MY_ZEROFILL)))) { pthread_mutex_unlock(&THR_LOCK_lock); return 1; @@ -125,6 +139,9 @@ 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) @@ -146,9 +163,18 @@ my_bool my_thread_init(void) void my_thread_end(void) { struct st_my_thread_var *tmp=my_thread_var; +#ifdef EXTRA_DEBUG + fprintf(stderr,"my_thread_end(): tmp=%p,thread_id=%ld\n", + tmp,pthread_self()); +#endif 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 + */ if (tmp->dbug) { free(tmp->dbug); @@ -160,12 +186,15 @@ void my_thread_end(void) #endif pthread_mutex_destroy(&tmp->mutex); #if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS) - free(tmp); + /* 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)); #endif } -#if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS) - pthread_setspecific(THR_KEY_mysys,0); -#endif } struct st_my_thread_var *_my_thread_var(void) |