예제 #1
0
void safe_hash_change(SAFE_HASH *hash, uchar *old_data, uchar *new_data)
{
  SAFE_HASH_ENTRY *entry, *next;
  DBUG_ENTER("safe_hash_change");

  mysql_rwlock_wrlock(&hash->mutex);

  for (entry= hash->root ; entry ; entry= next)
  {
    next= entry->next;
    if (entry->data == old_data)
    {
      if (new_data == hash->default_value)
      {
        if ((*entry->prev= entry->next))
          entry->next->prev= entry->prev;
        my_hash_delete(&hash->hash, (uchar*) entry);
      }
      else
        entry->data= new_data;
    }
  }

  mysql_rwlock_unlock(&hash->mutex);
  DBUG_VOID_RETURN;
}
예제 #2
0
파일: HashMap.hpp 프로젝트: carrotli/ansql
  bool remove(size_t i) {
    Entry* entry = (Entry*)my_hash_element(&m_hash, (ulong)i);
    if (entry == NULL)
      return false;

    if (my_hash_delete(&m_hash, (uchar*)entry))
      return false;
    return true;
  }
예제 #3
0
void mrn_free_long_term_share(MRN_LONG_TERM_SHARE *long_term_share)
{
  MRN_DBUG_ENTER_FUNCTION();
  {
    mrn::Lock lock(&mrn_long_term_share_mutex);
    my_hash_delete(&mrn_long_term_share, (uchar*) long_term_share);
  }
  mysql_mutex_destroy(&long_term_share->auto_inc_mutex);
  my_free(long_term_share);
  DBUG_VOID_RETURN;
}
예제 #4
0
파일: HashMap.hpp 프로젝트: carrotli/ansql
  bool remove(const K& k) {
    size_t key_length = sizeof(K);
    const void *key = get_key_ptr(&k, &key_length);
    Entry* entry= (Entry*)my_hash_search(&m_hash,
                                         (const uchar*)key, key_length);
    if (entry == NULL)
      return false;

    if (my_hash_delete(&m_hash, (uchar*)entry))
      return false;
    return true;
  }
예제 #5
0
int mrn_free_share(MRN_SHARE *share)
{
  MRN_DBUG_ENTER_FUNCTION();
  mrn::Lock lock(&mrn_open_tables_mutex);
  if (!--share->use_count)
  {
    my_hash_delete(&mrn_open_tables, (uchar*) share);
    if (share->wrapper_mode)
      plugin_unlock(NULL, share->plugin);
    mrn_free_share_alloc(share);
    thr_lock_delete(&share->lock);
    mysql_mutex_destroy(&share->record_mutex);
    if (share->wrapper_mode) {
#ifdef MRN_TABLE_SHARE_HAVE_LOCK_SHARE
      mysql_mutex_destroy(&(share->wrap_table_share->LOCK_share));
#endif
      mysql_mutex_destroy(&(share->wrap_table_share->LOCK_ha_data));
      free_root(&(share->wrap_table_share->mem_root), MYF(0));
    }
    my_free(share);
  }
  DBUG_RETURN(0);
}
예제 #6
0
my_bool safe_hash_set(SAFE_HASH *hash, const uchar *key, uint length,
                      uchar *data)
{
  SAFE_HASH_ENTRY *entry;
  my_bool error= 0;
  DBUG_ENTER("safe_hash_set");
  DBUG_PRINT("enter",("key: %.*s  data: 0x%lx", length, key, (long) data));

  mysql_rwlock_wrlock(&hash->mutex);
  entry= (SAFE_HASH_ENTRY*) my_hash_search(&hash->hash, key, length);

  if (data == hash->default_value)
  {
    /*
      The key is to be associated with the default entry. In this case
      we can just delete the entry (if it existed) from the hash as a
      search will return the default entry
    */
    if (!entry)          /* nothing to do */
      goto end;
    /* unlink entry from list */
    if ((*entry->prev= entry->next))
      entry->next->prev= entry->prev;
    my_hash_delete(&hash->hash, (uchar*) entry);
    goto end;
  }
  if (entry)
  {
    /* Entry existed;  Just change the pointer to point at the new data */
    entry->data= data;
  }
  else
  {
    if (!(entry= (SAFE_HASH_ENTRY *) my_malloc(sizeof(*entry) + length,
                                               MYF(MY_WME))))
    {
      error= 1;
      goto end;
    }
    entry->key= (uchar*) (entry +1);
    memcpy((char*) entry->key, (char*) key, length);
    entry->length= length;
    entry->data= data;
    /* Link entry to list */
    if ((entry->next= hash->root))
      entry->next->prev= &entry->next;
    entry->prev= &hash->root;
    hash->root= entry;
    if (my_hash_insert(&hash->hash, (uchar*) entry))
    {
      /* This can only happen if hash got out of memory */
      my_free(entry);
      error= 1;
      goto end;
    }
  }

end:
  mysql_rwlock_unlock(&hash->mutex);
  DBUG_RETURN(error);
}