Ignore some generated files

Don't return from my_thread_global_end() until all threads have called my_thread_end()
Bug#24387: Valgrind: my_thread_init (handle_sl sql, handle_one_conn, handle_slave_io)
parent 8aec636b
...@@ -1323,3 +1323,10 @@ win/vs8cache.txt ...@@ -1323,3 +1323,10 @@ win/vs8cache.txt
zlib/*.ds? zlib/*.ds?
zlib/*.vcproj zlib/*.vcproj
mysql-test/r/*.warnings mysql-test/r/*.warnings
bdb/dist/db.h
bdb/dist/db_config.h
bdb/dist/db_cxx.h
bdb/dist/db_int.h
bdb/dist/include.tcl
*.gcda
*.gcno
...@@ -677,14 +677,13 @@ struct st_my_thread_var ...@@ -677,14 +677,13 @@ struct st_my_thread_var
}; };
extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const)); extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const));
extern uint my_thread_end_wait_time;
#define my_thread_var (_my_thread_var()) #define my_thread_var (_my_thread_var())
#define my_errno my_thread_var->thr_errno #define my_errno my_thread_var->thr_errno
/* /*
Keep track of shutdown,signal, and main threads so that my_end() will not Keep track of shutdown,signal, and main threads so that my_end() will not
report errors with them report errors with them
*/ */
extern pthread_t shutdown_th, main_th, signal_th;
/* statistics_xxx functions are for not essential statistic */ /* statistics_xxx functions are for not essential statistic */
#ifndef thread_safe_increment #ifndef thread_safe_increment
......
...@@ -30,7 +30,10 @@ pthread_key(struct st_my_thread_var, THR_KEY_mysys); ...@@ -30,7 +30,10 @@ pthread_key(struct st_my_thread_var, THR_KEY_mysys);
#endif /* USE_TLS */ #endif /* USE_TLS */
pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open, pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,
THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap, THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_myisam,THR_LOCK_heap,
THR_LOCK_net, THR_LOCK_charset; THR_LOCK_net, THR_LOCK_charset, THR_LOCK_threads;
pthread_cond_t THR_COND_threads;
uint THR_thread_count= 0;
uint my_thread_end_wait_time= 5;
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
pthread_mutex_t LOCK_localtime_r; pthread_mutex_t LOCK_localtime_r;
#endif #endif
...@@ -79,7 +82,7 @@ my_bool my_thread_global_init(void) ...@@ -79,7 +82,7 @@ my_bool my_thread_global_init(void)
#endif #endif
#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP #ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP
/* /*
Set mutex type to "errorcheck" a.k.a "adaptive" Set mutex type to "errorcheck"
*/ */
pthread_mutexattr_init(&my_errorcheck_mutexattr); pthread_mutexattr_init(&my_errorcheck_mutexattr);
pthread_mutexattr_settype(&my_errorcheck_mutexattr, pthread_mutexattr_settype(&my_errorcheck_mutexattr,
...@@ -94,6 +97,8 @@ my_bool my_thread_global_init(void) ...@@ -94,6 +97,8 @@ my_bool my_thread_global_init(void)
pthread_mutex_init(&THR_LOCK_heap,MY_MUTEX_INIT_FAST); pthread_mutex_init(&THR_LOCK_heap,MY_MUTEX_INIT_FAST);
pthread_mutex_init(&THR_LOCK_net,MY_MUTEX_INIT_FAST); pthread_mutex_init(&THR_LOCK_net,MY_MUTEX_INIT_FAST);
pthread_mutex_init(&THR_LOCK_charset,MY_MUTEX_INIT_FAST); pthread_mutex_init(&THR_LOCK_charset,MY_MUTEX_INIT_FAST);
pthread_mutex_init(&THR_LOCK_threads,MY_MUTEX_INIT_FAST);
pthread_cond_init (&THR_COND_threads, NULL);
#if defined( __WIN__) || defined(OS2) #if defined( __WIN__) || defined(OS2)
win_pthread_init(); win_pthread_init();
#endif #endif
...@@ -114,6 +119,25 @@ my_bool my_thread_global_init(void) ...@@ -114,6 +119,25 @@ my_bool my_thread_global_init(void)
void my_thread_global_end(void) void my_thread_global_end(void)
{ {
struct timespec abstime;
set_timespec(abstime, my_thread_end_wait_time);
my_bool all_threads_killed= 1;
pthread_mutex_lock(&THR_LOCK_threads);
while (THR_thread_count)
{
int error= pthread_cond_timedwait(&THR_COND_threads, &THR_LOCK_threads,
&abstime);
if (error == ETIMEDOUT || error == ETIME)
{
if (THR_thread_count)
fprintf(stderr,"error in my_thread_global_end(): %d threads didn't exit\n",
THR_thread_count);
all_threads_killed= 0;
}
}
pthread_mutex_unlock(&THR_LOCK_threads);
pthread_key_delete(THR_KEY_mysys); pthread_key_delete(THR_KEY_mysys);
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_destroy(&my_fast_mutexattr); pthread_mutexattr_destroy(&my_fast_mutexattr);
...@@ -129,6 +153,11 @@ void my_thread_global_end(void) ...@@ -129,6 +153,11 @@ void my_thread_global_end(void)
pthread_mutex_destroy(&THR_LOCK_heap); pthread_mutex_destroy(&THR_LOCK_heap);
pthread_mutex_destroy(&THR_LOCK_net); pthread_mutex_destroy(&THR_LOCK_net);
pthread_mutex_destroy(&THR_LOCK_charset); pthread_mutex_destroy(&THR_LOCK_charset);
if (all_threads_killed)
{
pthread_mutex_destroy(&THR_LOCK_threads);
pthread_cond_destroy (&THR_COND_threads);
}
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) #if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
pthread_mutex_destroy(&LOCK_localtime_r); pthread_mutex_destroy(&LOCK_localtime_r);
#endif #endif
...@@ -154,9 +183,6 @@ my_bool my_thread_init(void) ...@@ -154,9 +183,6 @@ my_bool my_thread_init(void)
#ifdef EXTRA_DEBUG_THREADS #ifdef EXTRA_DEBUG_THREADS
fprintf(stderr,"my_thread_init(): thread_id=%ld\n",pthread_self()); fprintf(stderr,"my_thread_init(): thread_id=%ld\n",pthread_self());
#endif #endif
#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
pthread_mutex_lock(&THR_LOCK_lock);
#endif
#if !defined(__WIN__) || defined(USE_TLS) #if !defined(__WIN__) || defined(USE_TLS)
if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys)) if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys))
...@@ -174,7 +200,7 @@ my_bool my_thread_init(void) ...@@ -174,7 +200,7 @@ my_bool my_thread_init(void)
} }
pthread_setspecific(THR_KEY_mysys,tmp); pthread_setspecific(THR_KEY_mysys,tmp);
#else #else /* defined(__WIN__) && !(defined(USE_TLS) */
/* /*
Skip initialization if the thread specific variable is already initialized Skip initialization if the thread specific variable is already initialized
*/ */
...@@ -182,7 +208,6 @@ my_bool my_thread_init(void) ...@@ -182,7 +208,6 @@ my_bool my_thread_init(void)
goto end; goto end;
tmp= &THR_KEY_mysys; tmp= &THR_KEY_mysys;
#endif #endif
tmp->id= ++thread_id;
#if defined(__WIN__) && defined(EMBEDDED_LIBRARY) #if defined(__WIN__) && defined(EMBEDDED_LIBRARY)
tmp->thread_self= (pthread_t)getpid(); tmp->thread_self= (pthread_t)getpid();
#endif #endif
...@@ -190,10 +215,11 @@ my_bool my_thread_init(void) ...@@ -190,10 +215,11 @@ my_bool my_thread_init(void)
pthread_cond_init(&tmp->suspend, NULL); pthread_cond_init(&tmp->suspend, NULL);
tmp->init= 1; tmp->init= 1;
pthread_mutex_lock(&THR_LOCK_threads);
tmp->id= ++thread_id;
++THR_thread_count;
pthread_mutex_unlock(&THR_LOCK_threads);
end: end:
#if !defined(__WIN__) || defined(USE_TLS) || ! defined(SAFE_MUTEX)
pthread_mutex_unlock(&THR_LOCK_lock);
#endif
return error; return error;
} }
...@@ -232,6 +258,10 @@ void my_thread_end(void) ...@@ -232,6 +258,10 @@ void my_thread_end(void)
#if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS) #if (!defined(__WIN__) && !defined(OS2)) || defined(USE_TLS)
pthread_setspecific(THR_KEY_mysys,0); pthread_setspecific(THR_KEY_mysys,0);
#endif #endif
pthread_mutex_lock(&THR_LOCK_threads);
if (--THR_thread_count == 0)
pthread_cond_signal(&THR_COND_threads);
pthread_mutex_unlock(&THR_LOCK_threads);
} }
struct st_my_thread_var *_my_thread_var(void) struct st_my_thread_var *_my_thread_var(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment