Exemplo n.º 1
0
static TDHS_INLINE void destory_thd(THD *thd) {
    tb_assert(thd!=NULL);
    my_pthread_setspecific_ptr(THR_THD, 0);

    tdhs_mysql_mutex_lock(&LOCK_thread_count);
    delete thd;
    --thread_count;
    tdhs_mysql_mutex_unlock(&LOCK_thread_count);
    my_thread_end();
    (void) tdhs_mysql_cond_broadcast(&COND_thread_count);
}
bool servers_init(bool dont_read_servers_table)
{
  THD  *thd;
  bool return_val= FALSE;
  DBUG_ENTER("servers_init");

  /* init the mutex */
  if (my_rwlock_init(&THR_LOCK_servers, NULL))
    DBUG_RETURN(TRUE);

  /* initialise our servers cache */
  if (hash_init(&servers_cache, system_charset_info, 32, 0, 0,
                (hash_get_key) servers_cache_get_key, 0, 0))
  {
    return_val= TRUE; /* we failed, out of memory? */
    goto end;
  }

  /* Initialize the mem root for data */
  init_alloc_root(&mem, ACL_ALLOC_BLOCK_SIZE, 0);

  if (dont_read_servers_table)
    goto end;

  /*
    To be able to run this from boot, we allocate a temporary THD
  */
  if (!(thd=new THD))
    DBUG_RETURN(TRUE);
  thd->thread_stack= (char*) &thd;
  thd->store_globals();
  lex_start(thd);
  /*
    It is safe to call servers_reload() since servers_* arrays and hashes which
    will be freed there are global static objects and thus are initialized
    by zeros at startup.
  */
  return_val= servers_reload(thd);
  delete thd;
  /* Remember that we don't have a THD */
  my_pthread_setspecific_ptr(THR_THD,  0);

end:
  DBUG_RETURN(return_val);
}
Exemplo n.º 3
0
static TDHS_INLINE THD* init_THD(char* db, const void *stack_bottom,
                                 bool need_write) {
    THD *thd = NULL;
    my_thread_init();
    thd = new THD;
    if (thd == NULL) {
        my_thread_end();
        return NULL;
    }
    thd->thread_stack = (char*) stack_bottom;
    easy_debug_log("TDHS:thread_stack = %p sizeof(THD)=%zu sizeof(mtx)=%zu ",
                   thd->thread_stack, sizeof(THD), sizeof(LOCK_thread_count));
    thd->store_globals();
    thd->system_thread = static_cast<enum_thread_type>(1 << 30UL);
    const NET v = { 0 };
    thd->net = v;
    if (need_write) {
        //for write
#if MYSQL_VERSION_ID >= 50505
        thd->variables.option_bits |= OPTION_BIN_LOG;
#else
        thd->options |= OPTION_BIN_LOG;
#endif
    }
    //for db
    safeFree(thd->db);
    thd->db = db;
    my_pthread_setspecific_ptr(THR_THD, thd);

    tdhs_mysql_mutex_lock(&LOCK_thread_count);
    thd->thread_id = thread_id++;
    threads.append(thd);
    ++thread_count;
    tdhs_mysql_mutex_unlock(&LOCK_thread_count);
    return thd;
}
Exemplo n.º 4
0
int set_mysys_var(struct st_my_thread_var *mysys_var)
{
  if (THR_KEY_mysys_initialized)
    return my_pthread_setspecific_ptr(THR_KEY_mysys, mysys_var);
  return 0;
}