diff options
author | Dmitry Lenev <dlenev@mysql.com> | 2010-07-01 19:48:56 +0400 |
---|---|---|
committer | Dmitry Lenev <dlenev@mysql.com> | 2010-07-01 19:48:56 +0400 |
commit | 6afc935c40220440ef59607bccca3172fbadcd32 (patch) | |
tree | 39e13585904aa04c993f5878be83bed4ce1ffe63 /sql/sql_hset.h | |
parent | 10582e2abec2e05589125131bf0150c568a7cc31 (diff) | |
download | mariadb-git-6afc935c40220440ef59607bccca3172fbadcd32.tar.gz |
Another follow-up for 5.5 version of fix for bug#54360
"Deadlock DROP/ALTER/CREATE DATABASE with open HANDLER".
Fixes production build which was broken by the fix for
bug#54360 due to missing instantiation of some Hash_set
template's methods.
Circumvent requirement of explicit instantiation of
non-inline methods by making all Hash_set methods
inline.
Diffstat (limited to 'sql/sql_hset.h')
-rw-r--r-- | sql/sql_hset.h | 74 |
1 files changed, 27 insertions, 47 deletions
diff --git a/sql/sql_hset.h b/sql/sql_hset.h index c3b98b881f5..2ea70b91da8 100644 --- a/sql/sql_hset.h +++ b/sql/sql_hset.h @@ -33,12 +33,18 @@ public: Constructs an empty hash. Does not allocate memory, it is done upon the first insert. Thus does not cause or return errors. */ - Hash_set(); + Hash_set() + { + my_hash_clear(&m_hash); + } /** Destroy the hash by freeing the buckets table. Does not call destructors for the elements. */ - ~Hash_set(); + ~Hash_set() + { + my_hash_free(&m_hash); + } /** Insert a single value into a hash. Does not tell whether the value was inserted -- if an identical value existed, @@ -48,7 +54,15 @@ public: @retval FALSE OK. The value either was inserted or existed in the hash. */ - bool insert(T *value); + bool insert(T *value) + { + my_hash_init_opt(&m_hash, &my_charset_bin, START_SIZE, 0, 0, K, 0, MYF(0)); + size_t key_len; + const uchar *key= K(reinterpret_cast<uchar*>(value), &key_len, FALSE); + if (my_hash_search(&m_hash, key, key_len) == NULL) + return my_hash_insert(&m_hash, reinterpret_cast<uchar *>(value)); + return FALSE; + } /** Is this hash set empty? */ bool is_empty() const { return m_hash.records == 0; } /** Returns the number of unique elements. */ @@ -57,12 +71,20 @@ public: class Iterator { public: - Iterator(Hash_set &hash_set); + Iterator(Hash_set &hash_set) + : m_hash(&hash_set.m_hash), + m_idx(0) + {} /** Return the current element and reposition the iterator to the next element. */ - inline T *operator++(int); + inline T *operator++(int) + { + if (m_idx < m_hash->records) + return reinterpret_cast<T*>(my_hash_element(m_hash, m_idx++)); + return NULL; + } void rewind() { m_idx= 0; } private: HASH *m_hash; @@ -72,46 +94,4 @@ private: HASH m_hash; }; - -template <typename T, my_hash_get_key K> -Hash_set<T, K>::Hash_set() -{ - my_hash_clear(&m_hash); -} - - -template <typename T, my_hash_get_key K> -Hash_set<T, K>::~Hash_set() -{ - my_hash_free(&m_hash); -} - - -template <typename T, my_hash_get_key K> -bool Hash_set<T, K>::insert(T *value) -{ - my_hash_init_opt(&m_hash, &my_charset_bin, START_SIZE, 0, 0, K, 0, MYF(0)); - size_t key_len; - const uchar *key= K(reinterpret_cast<uchar*>(value), &key_len, FALSE); - if (my_hash_search(&m_hash, key, key_len) == NULL) - return my_hash_insert(&m_hash, reinterpret_cast<uchar *>(value)); - return FALSE; -} - - -template <typename T, my_hash_get_key K> -Hash_set<T, K>::Iterator::Iterator(Hash_set<T, K> &set_arg) - :m_hash(&set_arg.m_hash), - m_idx(0) -{} - - -template <typename T, my_hash_get_key K> -inline T *Hash_set<T, K>::Iterator::operator++(int) -{ - if (m_idx < m_hash->records) - return reinterpret_cast<T*>(my_hash_element(m_hash, m_idx++)); - return NULL; -} - #endif // SQL_HSET_INCLUDED |