Ejemplo n.º 1
0
/*
  We initialise the hashes for deadlock detection lazily.
  This greatly helps with performance when lots of mutexes are initiased but
  only a few of them are actually used (eg. XtraDB).
*/
static int safe_mutex_lazy_init_deadlock_detection(safe_mutex_t *mp)
{
  if (!my_multi_malloc(MY_FAE | MY_WME,
                       &mp->locked_mutex, sizeof(*mp->locked_mutex),
                       &mp->used_mutex, sizeof(*mp->used_mutex), NullS))
  {
    /* Disable deadlock handling for this mutex */
    mp->create_flags|= MYF_NO_DEADLOCK_DETECTION;
    mp->active_flags|= MYF_NO_DEADLOCK_DETECTION;
    return 1;                                   /* Error */
  }

  pthread_mutex_lock(&THR_LOCK_mutex);
  mp->id= ++safe_mutex_id;
  pthread_mutex_unlock(&THR_LOCK_mutex);
  my_hash_init2(mp->locked_mutex, 64, &my_charset_bin,
             128,
             offsetof(safe_mutex_deadlock_t, id),
             sizeof(mp->id),
             0, 0, 0, HASH_UNIQUE);
  my_hash_init2(mp->used_mutex, 64, &my_charset_bin,
             128,
             offsetof(safe_mutex_t, id),
             sizeof(mp->id),
             0, 0, 0, HASH_UNIQUE);
  return 0;
}
Ejemplo n.º 2
0
  HashMap(ulong initial_size = 1024, uint grow_size = 256) {

    assert(my_init_done);

    if (my_hash_init2(&m_hash,
                      grow_size,
                      &my_charset_bin, // charset
                      initial_size,    // default_array_elements
                      0,               // key_offset
                      sizeof(K),       // key_length
                      G == HashMap__get_key ? NULL : _get_key, // get_key,
                      free_element,    // free_element
                      HASH_UNIQUE,     // flags
                      PSI_INSTRUMENT_ME
                      ))
      abort();
  }