void thr_print_locks(void) { LIST *list; uint count=0; mysql_mutex_lock(&THR_LOCK_lock); puts("Current locks:"); for (list= thr_lock_thread_list; list && count++ < MAX_THREADS; list= list_rest(list)) { THR_LOCK *lock=(THR_LOCK*) list->data; mysql_mutex_lock(&lock->mutex); printf("lock: 0x%lx:",(ulong) lock); if ((lock->write_wait.data || lock->read_wait.data) && (! lock->read.data && ! lock->write.data)) printf(" WARNING: "); if (lock->write.data) printf(" write"); if (lock->write_wait.data) printf(" write_wait"); if (lock->read.data) printf(" read"); if (lock->read_wait.data) printf(" read_wait"); puts(""); thr_print_lock("write",&lock->write); thr_print_lock("write_wait",&lock->write_wait); thr_print_lock("read",&lock->read); thr_print_lock("read_wait",&lock->read_wait); mysql_mutex_unlock(&lock->mutex); puts(""); } fflush(stdout); mysql_mutex_unlock(&THR_LOCK_lock); }
FILE *my_fopen(const char *filename, int flags, myf MyFlags) { FILE *fd; char type[5]; char *dup_filename= NULL; DBUG_ENTER("my_fopen"); DBUG_PRINT("my",("Name: '%s' flags: %d MyFlags: %d", filename, flags, MyFlags)); make_ftype(type,flags); #ifdef _WIN32 fd= my_win_fopen(filename, type); #else fd= fopen(filename, type); #endif if (fd != 0) { /* The test works if MY_NFILE < 128. The problem is that fileno() is char on some OS (SUNOS). Actually the filename save isn't that important so we can ignore if this doesn't work. */ int filedesc= my_fileno(fd); if ((uint)filedesc >= my_file_limit) { mysql_mutex_lock(&THR_LOCK_open); my_stream_opened++; mysql_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ } dup_filename= my_strdup(key_memory_my_file_info, filename, MyFlags); if (dup_filename != NULL) { mysql_mutex_lock(&THR_LOCK_open); my_file_info[filedesc].name= dup_filename; my_stream_opened++; my_file_total_opened++; my_file_info[filedesc].type= STREAM_BY_FOPEN; mysql_mutex_unlock(&THR_LOCK_open); DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); DBUG_RETURN(fd); } (void) my_fclose(fd,MyFlags); set_my_errno(ENOMEM); } else set_my_errno(errno); DBUG_PRINT("error",("Got error %d on open",my_errno())); if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) { char errbuf[MYSYS_STRERROR_SIZE]; my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND : EE_CANTCREATEFILE, MYF(0), filename, my_errno(), my_strerror(errbuf, sizeof(errbuf), my_errno())); } DBUG_RETURN((FILE*) 0); } /* my_fopen */
my_bool check_table_is_closed(const char *name, const char *where) { char filename[FN_REFLEN]; LIST *pos; DBUG_ENTER("check_table_is_closed"); (void) fn_format(filename,name,"",MI_NAME_IEXT,4+16+32); mysql_mutex_lock(&THR_LOCK_myisam); for (pos=myisam_open_list ; pos ; pos=pos->next) { MI_INFO *info=(MI_INFO*) pos->data; MYISAM_SHARE *share=info->s; if (!strcmp(share->unique_file_name,filename)) { if (share->last_version) { mysql_mutex_unlock(&THR_LOCK_myisam); fprintf(stderr,"Warning: Table: %s is open on %s\n", name,where); DBUG_PRINT("warning",("Table: %s is open on %s", name,where)); DBUG_RETURN(1); } } } mysql_mutex_unlock(&THR_LOCK_myisam); DBUG_RETURN(0); }
int mi_panic(enum ha_panic_function flag) { int error=0; LIST *list_element,*next_open; MI_INFO *info; DBUG_ENTER("mi_panic"); mysql_mutex_lock(&THR_LOCK_myisam); for (list_element=myisam_open_list ; list_element ; list_element=next_open) { next_open=list_element->next; /* Save if close */ info=(MI_INFO*) list_element->data; switch (flag) { case HA_PANIC_CLOSE: mysql_mutex_unlock(&THR_LOCK_myisam); /* Not exactly right... */ if (mi_close(info)) error=my_errno(); mysql_mutex_lock(&THR_LOCK_myisam); break; case HA_PANIC_WRITE: /* Do this to free databases */ if (flush_key_blocks(info->s->key_cache, keycache_thread_var(), info->s->kfile, FLUSH_RELEASE)) error=my_errno(); if (info->opt_flag & WRITE_CACHE_USED) if (flush_io_cache(&info->rec_cache)) error=my_errno(); if (info->opt_flag & READ_CACHE_USED) { if (flush_io_cache(&info->rec_cache)) error=my_errno(); reinit_io_cache(&info->rec_cache,READ_CACHE,0, (pbool) (info->lock_type != F_UNLCK),1); } if (info->lock_type != F_UNLCK && ! info->was_locked) { info->was_locked=info->lock_type; if (mi_lock_database(info,F_UNLCK)) error=my_errno(); } case HA_PANIC_READ: /* Restore to before WRITE */ if (info->was_locked) { if (mi_lock_database(info, info->was_locked)) error=my_errno(); info->was_locked=0; } break; } } if (flag == HA_PANIC_CLOSE) { (void) mi_log(0); /* Close log if neaded */ ft_free_stopwords(); } mysql_mutex_unlock(&THR_LOCK_myisam); if (!error) DBUG_RETURN(0); set_my_errno(error); DBUG_RETURN(error); } /* mi_panic */
FILE *my_fopen(const char *filename, int flags, myf MyFlags) { FILE *fd; char type[5]; DBUG_ENTER("my_fopen"); DBUG_PRINT("my",("Name: '%s' flags: %d MyFlags: %d", filename, flags, MyFlags)); make_ftype(type,flags); #ifdef _WIN32 fd= my_win_fopen(filename, type); #else fd= fopen(filename, type); #endif if (fd != 0) { /* The test works if MY_NFILE < 128. The problem is that fileno() is char on some OS (SUNOS). Actually the filename save isn't that important so we can ignore if this doesn't work. */ int filedesc= my_fileno(fd); if ((uint)filedesc >= my_file_limit) { thread_safe_increment(my_stream_opened,&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ } mysql_mutex_lock(&THR_LOCK_open); if ((my_file_info[filedesc].name= (char*) my_strdup(filename,MyFlags))) { my_stream_opened++; my_file_total_opened++; my_file_info[filedesc].type= STREAM_BY_FOPEN; mysql_mutex_unlock(&THR_LOCK_open); DBUG_PRINT("exit",("stream: 0x%lx", (long) fd)); DBUG_RETURN(fd); } mysql_mutex_unlock(&THR_LOCK_open); (void) my_fclose(fd,MyFlags); my_errno=ENOMEM; } else my_errno=errno; DBUG_PRINT("error",("Got error %d on open",my_errno)); if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) my_error((flags & O_RDONLY) || (flags == O_RDONLY ) ? EE_FILENOTFOUND : EE_CANTCREATEFILE, MYF(ME_BELL+ME_WAITTANG), filename, my_errno); DBUG_RETURN((FILE*) 0); } /* my_fopen */
File my_register_filename(File fd, const char *FileName, enum file_type type_of_file, uint error_message_number, myf MyFlags) { char *dup_filename= NULL; DBUG_ENTER("my_register_filename"); if ((int) fd >= MY_FILE_MIN) { if ((uint) fd >= my_file_limit) { #if defined(_WIN32) my_errno= EMFILE; #else mysql_mutex_lock(&THR_LOCK_open); my_file_opened++; mysql_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(fd); /* safeguard */ #endif } else { dup_filename= my_strdup(key_memory_my_file_info, FileName, MyFlags); if (dup_filename != NULL) { mysql_mutex_lock(&THR_LOCK_open); my_file_info[fd].name= dup_filename; my_file_opened++; my_file_total_opened++; my_file_info[fd].type = type_of_file; mysql_mutex_unlock(&THR_LOCK_open); DBUG_PRINT("exit",("fd: %d",fd)); DBUG_RETURN(fd); } my_errno= ENOMEM; } (void) my_close(fd, MyFlags); } else my_errno= errno; DBUG_PRINT("error",("Got error %d on open", my_errno)); if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) { char errbuf[MYSYS_STRERROR_SIZE]; if (my_errno == EMFILE) error_message_number= EE_OUT_OF_FILERESOURCES; DBUG_PRINT("error",("print err: %d",error_message_number)); my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG), FileName, my_errno, my_strerror(errbuf, sizeof(errbuf), my_errno)); } DBUG_RETURN(-1); }
int my_close(File fd, myf MyFlags) { int err; DBUG_ENTER("my_close"); DBUG_PRINT("my",("fd: %d MyFlags: %d",fd, MyFlags)); mysql_mutex_lock(&THR_LOCK_open); #ifndef _WIN32 do { err= close(fd); } while (err == -1 && errno == EINTR); #else err= my_win_close(fd); #endif if (err) { DBUG_PRINT("error",("Got error %d on close",err)); my_errno=errno; if (MyFlags & (MY_FAE | MY_WME)) { char errbuf[MYSYS_STRERROR_SIZE]; my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), my_filename(fd), my_errno, my_strerror(errbuf, sizeof(errbuf), my_errno)); } } if ((uint) fd < my_file_limit && my_file_info[fd].type != UNOPEN) { my_free(my_file_info[fd].name); my_file_info[fd].type = UNOPEN; } my_file_opened--; mysql_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(err); } /* my_close */
void mi_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache) { LIST *pos; DBUG_ENTER("mi_change_key_cache"); /* Lock list to ensure that no one can close the table while we manipulate it */ mysql_mutex_lock(&THR_LOCK_myisam); for (pos=myisam_open_list ; pos ; pos=pos->next) { MI_INFO *info= (MI_INFO*) pos->data; MYISAM_SHARE *share= info->s; if (share->key_cache == old_key_cache) mi_assign_to_key_cache(info, (ulonglong) ~0, new_key_cache); } /* We have to do the following call while we have the lock on the MyISAM list structure to ensure that another thread is not trying to open a new table that will be associted with the old key cache */ multi_key_cache_change(old_key_cache, new_key_cache); mysql_mutex_unlock(&THR_LOCK_myisam); DBUG_VOID_RETURN; }
/* Close a stream */ int my_fclose(FILE *fd, myf MyFlags) { int err,file; DBUG_ENTER("my_fclose"); DBUG_PRINT("my",("stream: 0x%lx MyFlags: %d", (long) fd, MyFlags)); mysql_mutex_lock(&THR_LOCK_open); file= my_fileno(fd); #ifndef _WIN32 err= fclose(fd); #else err= my_win_fclose(fd); #endif if(err < 0) { set_my_errno(errno); if (MyFlags & (MY_FAE | MY_WME)) { char errbuf[MYSYS_STRERROR_SIZE]; my_error(EE_BADCLOSE, MYF(0), my_filename(file), my_errno(), my_strerror(errbuf, sizeof(errbuf), my_errno())); } } else my_stream_opened--; if ((uint) file < my_file_limit && my_file_info[file].type != UNOPEN) { my_file_info[file].type = UNOPEN; my_free(my_file_info[file].name); } mysql_mutex_unlock(&THR_LOCK_open); DBUG_RETURN(err); } /* my_fclose */
my_bool my_thread_init() { struct st_my_thread_var *tmp; if (!my_thread_global_init_done) return TRUE; /* cannot proceed with unintialized library */ if (mysys_thread_var()) return FALSE; #ifdef _MSC_VER install_sigabrt_handler(); #endif if (!(tmp= (struct st_my_thread_var *) calloc(1, sizeof(*tmp)))) return TRUE; mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST); mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend); tmp->stack_ends_here= (char*)&tmp + STACK_DIRECTION * (long)my_thread_stack_size; mysql_mutex_lock(&THR_LOCK_threads); tmp->id= ++thread_id; ++THR_thread_count; mysql_mutex_unlock(&THR_LOCK_threads); set_mysys_thread_var(tmp); return FALSE; }
void thr_unlock(THR_LOCK_DATA *data) { THR_LOCK *lock=data->lock; enum thr_lock_type lock_type=data->type; DBUG_ENTER("thr_unlock"); DBUG_PRINT("lock",("data: 0x%lx thread: 0x%x lock: 0x%lx", (long) data, data->owner->thread_id, (long) lock)); mysql_mutex_lock(&lock->mutex); check_locks(lock,"start of release lock",0); if (((*data->prev)=data->next)) /* remove from lock-list */ data->next->prev= data->prev; else if (lock_type <= TL_READ_NO_INSERT) lock->read.last=data->prev; else lock->write.last=data->prev; if (lock_type >= TL_WRITE_CONCURRENT_INSERT) { if (lock->update_status) (*lock->update_status)(data->status_param); } else { if (lock->restore_status) (*lock->restore_status)(data->status_param); } if (lock_type == TL_READ_NO_INSERT) lock->read_no_write_count--; data->type=TL_UNLOCK; /* Mark unlocked */ MYSQL_UNLOCK_TABLE(data->m_psi); check_locks(lock,"after releasing lock",1); wake_up_waiters(lock); mysql_mutex_unlock(&lock->mutex); DBUG_VOID_RETURN; }
int audit_log_buffer_write(audit_log_buffer_t *log, const char *buf, size_t len) { if (len > log->size) return(1); mysql_mutex_lock(&log->mutex); loop: if (log->write_pos + len < log->flush_pos + log->size) { size_t wrlen= min(len, log->size - (log->write_pos % log->size)); memcpy(log->buf + (log->write_pos % log->size), buf, wrlen); if (wrlen < len) memcpy(log->buf, buf + wrlen, len - wrlen); log->write_pos= log->write_pos + len; DBUG_ASSERT(log->write_pos >= log->flush_pos); } else { if (!log->drop_if_full) { mysql_cond_wait(&log->flushed_cond, &log->mutex); goto loop; } } if (log->write_pos > log->flush_pos + log->size / 2) { mysql_cond_signal(&log->written_cond); } mysql_mutex_unlock(&log->mutex); return(0); }
void thr_abort_locks(THR_LOCK *lock, my_bool upgrade_lock) { THR_LOCK_DATA *data; DBUG_ENTER("thr_abort_locks"); mysql_mutex_lock(&lock->mutex); for (data=lock->read_wait.data; data ; data=data->next) { data->type=TL_UNLOCK; /* Mark killed */ /* It's safe to signal the cond first: we're still holding the mutex. */ mysql_cond_signal(data->cond); data->cond=0; /* Removed from list */ } for (data=lock->write_wait.data; data ; data=data->next) { data->type=TL_UNLOCK; mysql_cond_signal(data->cond); data->cond=0; } lock->read_wait.last= &lock->read_wait.data; lock->write_wait.last= &lock->write_wait.data; lock->read_wait.data=lock->write_wait.data=0; if (upgrade_lock && lock->write.data) lock->write.data->type=TL_WRITE_ONLY; mysql_mutex_unlock(&lock->mutex); DBUG_VOID_RETURN; }
int logger_vprintf(LOGGER_HANDLE *log, const char* fmt, va_list ap) { int result; my_off_t filesize; char cvtbuf[1024]; size_t n_bytes; mysql_mutex_lock(&log->lock); if (log->rotations > 0) if ((filesize= my_tell(log->file, MYF(0))) == (my_off_t) -1 || ((unsigned long long)filesize >= log->size_limit && do_rotate(log))) { result= -1; errno= my_errno; goto exit; /* Log rotation needed but failed */ } n_bytes= my_vsnprintf(cvtbuf, sizeof(cvtbuf), fmt, ap); if (n_bytes >= sizeof(cvtbuf)) n_bytes= sizeof(cvtbuf) - 1; result= my_write(log->file, (uchar *) cvtbuf, n_bytes, MYF(0)); exit: mysql_mutex_unlock(&log->lock); return result; }
int logger_rotate(LOGGER_HANDLE *log) { int result; mysql_mutex_lock(&log->lock); result= do_rotate(log); mysql_mutex_unlock(&log->lock); return result; }
void heap_drop_table(HP_INFO *info) { DBUG_ENTER("heap_drop_table"); mysql_mutex_lock(&THR_LOCK_heap); heap_try_free(info->s); mysql_mutex_unlock(&THR_LOCK_heap); DBUG_VOID_RETURN; }
int heap_close(HP_INFO *info) { int tmp; DBUG_ENTER("heap_close"); mysql_mutex_lock(&THR_LOCK_heap); tmp= hp_close(info); mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(tmp); }
void thr_lock_delete(THR_LOCK *lock) { DBUG_ENTER("thr_lock_delete"); mysql_mutex_lock(&THR_LOCK_lock); thr_lock_thread_list=list_delete(thr_lock_thread_list,&lock->list); mysql_mutex_unlock(&THR_LOCK_lock); mysql_mutex_destroy(&lock->mutex); DBUG_VOID_RETURN; }
struct tm *gmtime_r(const time_t *clock, struct tm *res) { struct tm *tmp; mysql_mutex_lock(&LOCK_localtime_r); tmp= gmtime(clock); *res= *tmp; mysql_mutex_unlock(&LOCK_localtime_r); return res; }
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; }
char *my_tmpdir(MY_TMPDIR *tmpdir) { char *dir; if (!tmpdir->max) return tmpdir->list[0]; mysql_mutex_lock(&tmpdir->mutex); dir=tmpdir->list[tmpdir->cur]; tmpdir->cur= (tmpdir->cur == tmpdir->max) ? 0 : tmpdir->cur+1; mysql_mutex_unlock(&tmpdir->mutex); return dir; }
static void audit_log_flush(audit_log_buffer_t *log) { mysql_mutex_lock(&log->mutex); while (log->flush_pos == log->write_pos) { struct timespec abstime; if (log->stop) { mysql_mutex_unlock(&log->mutex); return; } set_timespec(abstime, 1); mysql_cond_timedwait(&log->written_cond, &log->mutex, &abstime); } if (log->flush_pos > log->write_pos % log->size) { mysql_mutex_unlock(&log->mutex); log->write_func(log->write_func_data, log->buf + log->flush_pos, log->size - log->flush_pos, LOG_RECORD_INCOMPLETE); mysql_mutex_lock(&log->mutex); log->flush_pos= 0; log->write_pos%= log->size; } else { size_t flushlen= log->write_pos - log->flush_pos; mysql_mutex_unlock(&log->mutex); log->write_func(log->write_func_data, log->buf + log->flush_pos, flushlen, LOG_RECORD_COMPLETE); mysql_mutex_lock(&log->mutex); log->flush_pos+= flushlen; } DBUG_ASSERT(log->write_pos >= log->flush_pos); mysql_cond_broadcast(&log->flushed_cond); mysql_mutex_unlock(&log->mutex); }
void _ma_update_status_with_lock(MARIA_HA *info) { my_bool locked= 0; if (info->state == &info->state_save) { locked= 1; mysql_mutex_lock(&info->s->lock.mutex); } (*info->s->lock.update_status)(info); if (locked) mysql_mutex_unlock(&info->s->lock.mutex); }
int heap_rename(const char *old_name, const char *new_name) { HP_SHARE *info; char *name_buff; DBUG_ENTER("heap_rename"); mysql_mutex_lock(&THR_LOCK_heap); if ((info = hp_find_named_heap(old_name))) { if (!(name_buff=(char*) my_strdup(hp_key_memory_HP_SHARE, new_name, MYF(MY_WME)))) { mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(my_errno()); } my_free(info->name); info->name=name_buff; } mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(0); }
my_bool my_thread_init(void) { struct st_my_thread_var *tmp; my_bool error=0; if (!my_thread_global_init_done) return 1; /* cannot proceed with unintialized library */ #ifdef EXTRA_DEBUG_THREADS my_message_local(INFORMATION_LEVEL, "my_thread_init(): thread_id: 0x%lx", (ulong) pthread_self()); #endif if (_my_thread_var()) { #ifdef EXTRA_DEBUG_THREADS my_message_local(WARNING_LEVEL, "my_thread_init() called more than once in thread 0x%lx", (long) pthread_self()); #endif goto end; } #ifdef _MSC_VER install_sigabrt_handler(); #endif if (!(tmp= (struct st_my_thread_var *) calloc(1, sizeof(*tmp)))) { error= 1; goto end; } set_mysys_var(tmp); tmp->pthread_self= pthread_self(); mysql_mutex_init(key_my_thread_var_mutex, &tmp->mutex, MY_MUTEX_INIT_FAST); mysql_cond_init(key_my_thread_var_suspend, &tmp->suspend, NULL); tmp->stack_ends_here= (char*)&tmp + STACK_DIRECTION * (long)my_thread_stack_size; mysql_mutex_lock(&THR_LOCK_threads); tmp->id= ++thread_id; ++THR_thread_count; mysql_mutex_unlock(&THR_LOCK_threads); tmp->init= 1; #ifndef DBUG_OFF /* Generate unique name for thread */ (void) my_thread_name(); #endif end: return error; }
static void mi_update_status_with_lock(MI_INFO *info) { my_bool locked= 0; if (info->state == &info->save_state) { locked= 1; mysql_mutex_lock(&info->s->lock.mutex); } mi_update_status(info); if (locked) mysql_mutex_unlock(&info->s->lock.mutex); }
HP_INFO *heap_open(const char *name, int mode) { HP_INFO *info; HP_SHARE *share; DBUG_ENTER("heap_open"); mysql_mutex_lock(&THR_LOCK_heap); if (!(share= hp_find_named_heap(name))) { my_errno= ENOENT; mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(0); } if ((info= heap_open_from_share(share, mode))) { info->open_list.data= (void*) info; heap_open_list= list_add(heap_open_list,&info->open_list); } mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(info); }
/** Dereference a HEAP share and free it if it's not referenced. We don't check open_count for internal tables since they are always thread-local, i.e. referenced by a single thread. */ void heap_release_share(HP_SHARE *share, my_bool internal_table) { /* Couldn't open table; Remove the newly created table */ if (internal_table) hp_free(share); else { mysql_mutex_lock(&THR_LOCK_heap); if (--share->open_count == 0) hp_free(share); mysql_mutex_unlock(&THR_LOCK_heap); } }
int aby_rename(const char *old_name, const char *new_name) { reg1 HPA_SHARE *info; char *name_buff; DBUG_ENTER("aby_rename"); if(ABY_LOCK == ABY_HEAP) mysql_mutex_lock(&THR_LOCK_heap); if ((info = hpa_find_named_aby(old_name))) { if (!(name_buff=(char*) my_strdup(new_name,MYF(MY_WME)))) { if(ABY_LOCK == ABY_HEAP) mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(my_errno); } my_free(info->name); info->name=name_buff; } if(ABY_LOCK == ABY_HEAP) mysql_mutex_unlock(&THR_LOCK_heap); DBUG_RETURN(0); }
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); }