CHARSET_INFO *get_charset(uint cs_number, myf flags) { CHARSET_INFO *cs; MY_CHARSET_LOADER loader; if (cs_number == default_charset_info->number) return default_charset_info; my_pthread_once(&charsets_initialized, init_available_charsets); if (cs_number >= array_elements(all_charsets)) return NULL; my_charset_loader_init_mysys(&loader); cs= get_internal_charset(&loader, cs_number, flags); if (!cs && (flags & MY_WME)) { char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)], cs_string[23]; my_stpcpy(get_charsets_dir(index_file),MY_CHARSET_INDEX); cs_string[0]='#'; int10_to_str(cs_number, cs_string+1, 10); my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_string, index_file); } return cs; }
int my_rw_init(my_rw_lock_t *rwp) { pthread_condattr_t cond_attr; #ifdef _WIN32 /* Once initialization is used here rather than in my_init(), in order to - avoid my_init() pitfalls- (undefined order in which initialization should run) - be potentially useful C++ (static constructors) - just to simplify the API. Also, the overhead is of my_pthread_once is very small. */ static my_pthread_once_t once_control= MY_PTHREAD_ONCE_INIT; my_pthread_once(&once_control, check_srwlock_availability); if (have_srwlock) return srw_init(rwp); #endif pthread_mutex_init( &rwp->lock, MY_MUTEX_INIT_FAST); pthread_condattr_init( &cond_attr ); pthread_cond_init( &rwp->readers, &cond_attr ); pthread_cond_init( &rwp->writers, &cond_attr ); pthread_condattr_destroy(&cond_attr); rwp->state = 0; rwp->waiters = 0; #ifdef SAFE_MUTEX rwp->write_thread = 0; #endif return(0); }
uint get_charset_number(const char *charset_name, uint cs_flags) { uint id; my_pthread_once(&charsets_initialized, init_available_charsets); if ((id= get_charset_number_internal(charset_name, cs_flags))) return id; if ((charset_name= get_charset_name_alias(charset_name))) return get_charset_number_internal(charset_name, cs_flags); return 0; }
uint get_collation_number(const char *name) { uint id; char alias[64]; my_pthread_once(&charsets_initialized, init_available_charsets); if ((id= get_collation_number_internal(name))) return id; if ((name= get_collation_name_alias(name, alias, sizeof(alias)))) return get_collation_number_internal(name); return 0; }
const char *get_charset_name(uint charset_number) { CHARSET_INFO *cs; my_pthread_once(&charsets_initialized, init_available_charsets); cs=all_charsets[charset_number]; if (cs && (cs->number == charset_number) && cs->name ) return (char*) cs->name; return (char*) "?"; /* this mimics find_type() */ }
CHARSET_INFO *get_charset_by_name(const char *cs_name, myf flags) { uint cs_number; CHARSET_INFO *cs; my_pthread_once(&charsets_initialized, init_available_charsets); cs_number=get_collation_number(cs_name); cs= cs_number ? get_internal_charset(cs_number,flags) : NULL; if (!cs && (flags & MY_WME)) { char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)]; strmov(get_charsets_dir(index_file),MY_CHARSET_INDEX); my_error(EE_UNKNOWN_COLLATION, MYF(ME_BELL), cs_name, index_file); } return cs; }
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { /* Once initialization is used here rather than in my_init(), to 1) avoid my_init() pitfalls- undefined order in which initialization should run 2) be potentially useful C++ (in static constructors that run before main()) 3) just to simplify the API. Also, the overhead of my_pthread_once is very small. */ static my_pthread_once_t once_control= MY_PTHREAD_ONCE_INIT; my_pthread_once(&once_control, check_native_cond_availability); if (have_native_conditions) { my_InitializeConditionVariable(&cond->native_cond); return 0; } else return legacy_cond_init(cond, attr); }
CHARSET_INFO *get_charset_by_csname(const char *cs_name, uint cs_flags, myf flags) { uint cs_number; CHARSET_INFO *cs; DBUG_ENTER("get_charset_by_csname"); DBUG_PRINT("enter",("name: '%s'", cs_name)); my_pthread_once(&charsets_initialized, init_available_charsets); cs_number= get_charset_number(cs_name, cs_flags); cs= cs_number ? get_internal_charset(cs_number, flags) : NULL; if (!cs && (flags & MY_WME)) { char index_file[FN_REFLEN + sizeof(MY_CHARSET_INDEX)]; strmov(get_charsets_dir(index_file),MY_CHARSET_INDEX); my_error(EE_UNKNOWN_CHARSET, MYF(ME_BELL), cs_name, index_file); } DBUG_RETURN(cs); }