void audit_log_buffer_shutdown(audit_log_buffer_t *log) { log->stop= TRUE; pthread_join(log->flush_worker_thread, NULL); mysql_cond_destroy(&log->flushed_cond); mysql_cond_destroy(&log->written_cond); mysql_mutex_destroy(&log->mutex); free(log); }
void my_thread_global_end(void) { struct timespec abstime; my_bool all_threads_killed= 1; set_timespec(&abstime, my_thread_end_wait_time); mysql_mutex_lock(&THR_LOCK_threads); while (THR_thread_count > 0) { int error= mysql_cond_timedwait(&THR_COND_threads, &THR_LOCK_threads, &abstime); if (error == ETIMEDOUT || error == ETIME) { #ifndef _WIN32 /* We shouldn't give an error here, because if we don't have pthread_kill(), programs like mysqld can't ensure that all threads are killed when we enter here. */ if (THR_thread_count) /* purecov: begin inspected */ my_message_local(ERROR_LEVEL, "Error in my_thread_global_end(): " "%d threads didn't exit", THR_thread_count); /* purecov: end */ #endif all_threads_killed= 0; break; } } mysql_mutex_unlock(&THR_LOCK_threads); DBUG_ASSERT(THR_KEY_mysys_initialized); my_delete_thread_local_key(THR_KEY_mysys); THR_KEY_mysys_initialized= FALSE; #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 mysql_mutex_destroy(&THR_LOCK_malloc); mysql_mutex_destroy(&THR_LOCK_open); mysql_mutex_destroy(&THR_LOCK_lock); mysql_mutex_destroy(&THR_LOCK_myisam); mysql_mutex_destroy(&THR_LOCK_myisam_mmap); mysql_mutex_destroy(&THR_LOCK_heap); mysql_mutex_destroy(&THR_LOCK_net); mysql_mutex_destroy(&THR_LOCK_charset); if (all_threads_killed) { mysql_mutex_destroy(&THR_LOCK_threads); mysql_cond_destroy(&THR_COND_threads); } my_thread_global_init_done= 0; }
/** Re-initialize components initialized early with @c my_thread_global_init. Some mutexes were initialized before the instrumentation. Destroy + create them again, now that the instrumentation is in place. This is safe, since this function() is called before creating new threads, so the mutexes are not in use. */ void my_thread_global_reinit(void) { struct st_my_thread_var *tmp; DBUG_ASSERT(my_thread_global_init_done); #ifdef HAVE_PSI_INTERFACE my_init_mysys_psi_keys(); #endif mysql_mutex_destroy(&THR_LOCK_heap); mysql_mutex_init(key_THR_LOCK_heap, &THR_LOCK_heap, MY_MUTEX_INIT_FAST); mysql_mutex_destroy(&THR_LOCK_net); mysql_mutex_init(key_THR_LOCK_net, &THR_LOCK_net, MY_MUTEX_INIT_FAST); mysql_mutex_destroy(&THR_LOCK_myisam); mysql_mutex_init(key_THR_LOCK_myisam, &THR_LOCK_myisam, MY_MUTEX_INIT_SLOW); mysql_mutex_destroy(&THR_LOCK_malloc); mysql_mutex_init(key_THR_LOCK_malloc, &THR_LOCK_malloc, MY_MUTEX_INIT_FAST); mysql_mutex_destroy(&THR_LOCK_open); mysql_mutex_init(key_THR_LOCK_open, &THR_LOCK_open, MY_MUTEX_INIT_FAST); mysql_mutex_destroy(&THR_LOCK_charset); mysql_mutex_init(key_THR_LOCK_charset, &THR_LOCK_charset, MY_MUTEX_INIT_FAST); mysql_mutex_destroy(&THR_LOCK_threads); mysql_mutex_init(key_THR_LOCK_threads, &THR_LOCK_threads, MY_MUTEX_INIT_FAST); mysql_cond_destroy(&THR_COND_threads); mysql_cond_init(key_THR_COND_threads, &THR_COND_threads); tmp= mysys_thread_var(); DBUG_ASSERT(tmp); mysql_mutex_destroy(&tmp->mutex); mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST); mysql_cond_destroy(&tmp->suspend); mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend); }
/** WT_RESOURCE destructor It's called from lf_hash and takes a pointer to an LF_SLIST instance. WT_RESOURCE is located at arg+sizeof(LF_SLIST) */ static void wt_resource_destroy(uchar *arg) { WT_RESOURCE *rc= (WT_RESOURCE*)(arg+LF_HASH_OVERHEAD); DBUG_ENTER("wt_resource_destroy"); DBUG_ASSERT(rc->owners.elements == 0); rc_rwlock_destroy(rc); mysql_cond_destroy(&rc->cond); delete_dynamic(&rc->owners); DBUG_VOID_RETURN; }
int main(int argc, char **argv) { int error,i,first; ulong total_count,total_error,total_recover; MY_INIT(argv[0]); memset(&main_thread_keycache_var, 0, sizeof(st_keycache_thread_var)); mysql_cond_init(PSI_NOT_INSTRUMENTED, &main_thread_keycache_var.suspend); log_filename=myisam_log_filename; get_options(&argc,&argv); /* Number of MyISAM files we can have open at one time */ max_files= (my_set_max_open_files(MY_MIN(max_files, 8)) - 6) / 2; if (update) printf("Trying to %s MyISAM files according to log '%s'\n", (recover ? "recover" : "update"),log_filename); error= examine_log(log_filename,argv); if (update && ! error) puts("Tables updated successfully"); total_count=total_error=total_recover=0; for (i=first=0 ; command_name[i] ; i++) { if (com_count[i][0]) { if (!first++) { if (verbose || update) puts(""); puts("Commands Used count Errors Recover errors"); } printf("%-12s%9ld%10ld%17ld\n",command_name[i],com_count[i][0], com_count[i][1],com_count[i][2]); total_count+=com_count[i][0]; total_error+=com_count[i][1]; total_recover+=com_count[i][2]; } } if (total_count) printf("%-12s%9ld%10ld%17ld\n","Total",total_count,total_error, total_recover); if (re_open_count) printf("Had to do %d re-open because of too few possibly open files\n", re_open_count); (void) mi_panic(HA_PANIC_CLOSE); my_free_open_file_info(); my_end(test_info ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR); mysql_cond_destroy(&main_thread_keycache_var.suspend); exit(error); return 0; /* No compiler warning */ } /* main */
void my_thread_end(void) { struct st_my_thread_var *tmp; tmp= _my_thread_var(); #ifdef EXTRA_DEBUG_THREADS my_message_local(INFORMATION_LEVEL, "my_thread_end(): tmp: 0x%lx " "pthread_self: 0x%lx thread_id: %ld", (long) tmp, (long) pthread_self(), tmp ? (long) tmp->id : 0L); #endif #ifdef HAVE_PSI_INTERFACE /* Remove the instrumentation for this thread. This must be done before trashing st_my_thread_var, because the LF_HASH depends on it. */ PSI_THREAD_CALL(delete_current_thread)(); #endif if (tmp && tmp->init) { #if !defined(DBUG_OFF) /* tmp->dbug is allocated inside DBUG library */ if (tmp->dbug) { DBUG_POP(); free(tmp->dbug); tmp->dbug=0; } #endif mysql_cond_destroy(&tmp->suspend); mysql_mutex_destroy(&tmp->mutex); free(tmp); /* Decrement counter for number of running threads. We are using this in my_thread_global_end() to wait until all threads have called my_thread_end and thus freed all memory they have allocated in my_thread_init() and DBUG_xxxx */ mysql_mutex_lock(&THR_LOCK_threads); DBUG_ASSERT(THR_thread_count != 0); if (--THR_thread_count == 0) mysql_cond_signal(&THR_COND_threads); mysql_mutex_unlock(&THR_LOCK_threads); } set_mysys_var(NULL); }
int main(int argc __attribute__((unused)), char **argv) { MY_INIT("thd_template"); if (argv[1] && *argv[1]) DBUG_SET_INITIAL(argv[1]); mysql_mutex_init(0, &mutex, 0); mysql_cond_init(0, &cond, 0); pthread_attr_init(&thr_attr); pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); #ifdef MY_ATOMIC_MODE_RWLOCKS #if defined(HPUX11) || defined(__POWERPC__) /* showed to be very slow (scheduler-related) */ #define CYCLES 300 #else #define CYCLES 3000 #endif #else #define CYCLES 3000 #endif #define THREADS 30 diag("N CPUs: %d, atomic ops: %s", my_getncpus(), MY_ATOMIC_MODE); do_tests(); /* workaround until we know why it crashes randomly on some machine (BUG#22320). */ sleep(2); mysql_mutex_destroy(&mutex); mysql_cond_destroy(&cond); pthread_attr_destroy(&thr_attr); my_end(0); return exit_status(); }
int main(int argc,char *argv[]) { int error=0, subkeys; uint keylen, keylen2=0, inx, doc_cnt=0; float weight= 1.0; double gws, min_gws=0, avg_gws=0; MI_INFO *info; char buf[MAX_LEN], buf2[MAX_LEN], buf_maxlen[MAX_LEN], buf_min_gws[MAX_LEN]; ulong total=0, maxlen=0, uniq=0, max_doc_cnt=0; struct { MI_INFO *info; } aio0, *aio=&aio0; /* for GWS_IN_USE */ MY_INIT(argv[0]); memset(&main_thread_keycache_var, 0, sizeof(st_keycache_thread_var)); mysql_cond_init(PSI_NOT_INSTRUMENTED, &main_thread_keycache_var.suspend); if ((error= handle_options(&argc, &argv, my_long_options, get_one_option))) exit(error); if (count || dump) verbose=0; if (!count && !dump && !lstats && !query) stats=1; if (verbose) setbuf(stdout,NULL); if (argc < 2) usage(); { char *end; inx= (uint) my_strtoll(argv[1], &end, 10); if (*end) usage(); } init_key_cache(dflt_key_cache,MI_KEY_BLOCK_LENGTH,USE_BUFFER_INIT, 0, 0); if (!(info=mi_open(argv[0], O_RDONLY, HA_OPEN_ABORT_IF_LOCKED|HA_OPEN_FROM_SQL_LAYER))) { error=my_errno(); goto err; } *buf2=0; aio->info=info; if ((inx >= info->s->base.keys) || !(info->s->keyinfo[inx].flag & HA_FULLTEXT)) { printf("Key %d in table %s is not a FULLTEXT key\n", inx, info->filename); goto err; } mi_lock_database(info, F_EXTRA_LCK); info->lastpos= HA_OFFSET_ERROR; info->update|= HA_STATE_PREV_FOUND; while (!(error=mi_rnext(info,NULL,inx))) { keylen=*(info->lastkey); subkeys=ft_sintXkorr(info->lastkey+keylen+1); if (subkeys >= 0) ft_floatXget(weight, info->lastkey+keylen+1); my_snprintf(buf,MAX_LEN,"%.*s",(int) keylen,info->lastkey+1); my_casedn_str(default_charset_info,buf); total++; lengths[keylen]++; if (count || stats) { if (strcmp(buf, buf2)) { if (*buf2) { uniq++; avg_gws+=gws=GWS_IN_USE; if (count) printf("%9u %20.7f %s\n",doc_cnt,gws,buf2); if (maxlen<keylen2) { maxlen=keylen2; my_stpcpy(buf_maxlen, buf2); } if (max_doc_cnt < doc_cnt) { max_doc_cnt=doc_cnt; my_stpcpy(buf_min_gws, buf2); min_gws=gws; } } my_stpcpy(buf2, buf); keylen2=keylen; doc_cnt=0; } doc_cnt+= (subkeys >= 0 ? 1 : -subkeys); } if (dump) { if (subkeys>=0) printf("%9lx %20.7f %s\n", (long) info->lastpos,weight,buf); else printf("%9lx => %17d %s\n",(long) info->lastpos,-subkeys,buf); } if (verbose && (total%HOW_OFTEN_TO_WRITE)==0) printf("%10ld\r",total); } mi_lock_database(info, F_UNLCK); if (count || stats) { if (*buf2) { uniq++; avg_gws+=gws=GWS_IN_USE; if (count) printf("%9u %20.7f %s\n",doc_cnt,gws,buf2); if (maxlen<keylen2) { maxlen=keylen2; my_stpcpy(buf_maxlen, buf2); } if (max_doc_cnt < doc_cnt) { max_doc_cnt=doc_cnt; my_stpcpy(buf_min_gws, buf2); min_gws=gws; } } } if (stats) { count=0; for (inx=0;inx<256;inx++) { count+=lengths[inx]; if ((ulong) count >= total/2) break; } printf("Total rows: %lu\nTotal words: %lu\n" "Unique words: %lu\nLongest word: %lu chars (%s)\n" "Median length: %u\n" "Average global weight: %f\n" "Most common word: %lu times, weight: %f (%s)\n", (long) info->state->records, total, uniq, maxlen, buf_maxlen, inx, avg_gws/uniq, max_doc_cnt, min_gws, buf_min_gws); } if (lstats) { count=0; for (inx=0; inx<256; inx++) { count+=lengths[inx]; if (count && lengths[inx]) printf("%3u: %10lu %5.2f%% %20lu %4.1f%%\n", inx, (ulong) lengths[inx],100.0*lengths[inx]/total,(ulong) count, 100.0*count/total); } } err: if (error && error != HA_ERR_END_OF_FILE) printf("got error %d\n",my_errno()); if (info) mi_close(info); mysql_cond_destroy(&main_thread_keycache_var.suspend); return 0; }
void do_tests() { DBUG_ENTER("do_tests"); skip_all(": this module is not used in MySQL"); plan(12); compile_time_assert(THREADS >= 4); DBUG_PRINT("wt", ("================= initialization ===================")); bad= my_atomic_initialize(); ok(!bad, "my_atomic_initialize() returned %d", bad); mysql_cond_init(0, &thread_sync, 0); mysql_mutex_init(0, &lock, 0); wt_init(); for (cnt=0; cnt < THREADS; cnt++) mysql_mutex_init(0, & thds[cnt].lock, 0); { WT_RESOURCE_ID resid[4]; for (i=0; i < array_elements(resid); i++) { wt_thd_lazy_init(& thds[i].thd, & wt_deadlock_search_depth_short, & wt_timeout_short, & wt_deadlock_search_depth_long, & wt_timeout_long); resid[i].value= i+1; resid[i].type= &restype; } DBUG_PRINT("wt", ("================= manual test ===================")); #define ok_wait(X,Y, R) \ ok(wt_thd_will_wait_for(& thds[X].thd, & thds[Y].thd, &resid[R]) == 0, \ "thd[" #X "] will wait for thd[" #Y "]") #define ok_deadlock(X,Y,R) \ ok(wt_thd_will_wait_for(& thds[X].thd, & thds[Y].thd, &resid[R]) == WT_DEADLOCK, \ "thd[" #X "] will wait for thd[" #Y "] - deadlock") ok_wait(0,1,0); ok_wait(0,2,0); ok_wait(0,3,0); mysql_mutex_lock(&lock); bad= wt_thd_cond_timedwait(& thds[0].thd, &lock); mysql_mutex_unlock(&lock); ok(bad == WT_TIMEOUT, "timeout test returned %d", bad); ok_wait(0,1,0); ok_wait(1,2,1); ok_deadlock(2,0,2); mysql_mutex_lock(&lock); ok(wt_thd_cond_timedwait(& thds[0].thd, &lock) == WT_TIMEOUT, "as always"); ok(wt_thd_cond_timedwait(& thds[1].thd, &lock) == WT_TIMEOUT, "as always"); wt_thd_release_all(& thds[0].thd); wt_thd_release_all(& thds[1].thd); wt_thd_release_all(& thds[2].thd); wt_thd_release_all(& thds[3].thd); for (i=0; i < array_elements(resid); i++) { wt_thd_release_all(& thds[i].thd); wt_thd_destroy(& thds[i].thd); } mysql_mutex_unlock(&lock); } wt_deadlock_search_depth_short=6; wt_timeout_short=1000; wt_timeout_long= 100; wt_deadlock_search_depth_long=16; DBUG_PRINT("wt", ("================= stress test ===================")); diag("timeout_short=%lu us, deadlock_search_depth_short=%lu", wt_timeout_short, wt_deadlock_search_depth_short); diag("timeout_long=%lu us, deadlock_search_depth_long=%lu", wt_timeout_long, wt_deadlock_search_depth_long); #define test_kill_strategy(X) \ diag("kill strategy: " #X); \ DBUG_EXECUTE("reset_file", \ { rewind(DBUG_FILE); my_chsize(fileno(DBUG_FILE), 0, 0, MYF(0)); }); \ DBUG_PRINT("info", ("kill strategy: " #X)); \ kill_strategy=X; \ do_one_test(); test_kill_strategy(LATEST); test_kill_strategy(RANDOM); /* these two take looong time on sol10-amd64-a the server doesn't use this code now, so we disable these tests test_kill_strategy(YOUNGEST); test_kill_strategy(LOCKS); */ DBUG_PRINT("wt", ("================= cleanup ===================")); for (cnt=0; cnt < THREADS; cnt++) mysql_mutex_destroy(& thds[cnt].lock); wt_end(); mysql_mutex_destroy(&lock); mysql_cond_destroy(&thread_sync); DBUG_VOID_RETURN; }
void my_thread_destroy_internal_mutex(void) { mysql_mutex_destroy(&THR_LOCK_threads); mysql_mutex_destroy(&THR_LOCK_malloc); mysql_cond_destroy(&THR_COND_threads); }
static void my_thread_destory_thr_mutex(struct st_my_thread_var *var) { mysql_mutex_destroy(&var->mutex); mysql_cond_destroy(&var->suspend); }