diff options
author | monty@mysql.com <> | 2005-08-11 15:58:15 +0300 |
---|---|---|
committer | monty@mysql.com <> | 2005-08-11 15:58:15 +0300 |
commit | 7b80e62528abfa3b6dd5eb4d94cc6cee27ad590d (patch) | |
tree | 7d0b6e81295c86daf6c699dd29e763b6858d3b29 /sql/sp_cache.cc | |
parent | c954c09a1196386feb3ff3232c5016845b9f68f2 (diff) | |
download | mariadb-git-7b80e62528abfa3b6dd5eb4d94cc6cee27ad590d.tar.gz |
Cleanups during review of new code
Diffstat (limited to 'sql/sp_cache.cc')
-rw-r--r-- | sql/sp_cache.cc | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc index c8f0ed6ba2d..31cecff6e50 100644 --- a/sql/sp_cache.cc +++ b/sql/sp_cache.cc @@ -22,7 +22,7 @@ #include "sp_head.h" static pthread_mutex_t Cversion_lock; -static ulong Cversion = 0; +static ulong volatile Cversion = 0; void sp_cache_init() @@ -30,6 +30,7 @@ sp_cache_init() pthread_mutex_init(&Cversion_lock, MY_MUTEX_INIT_FAST); } + void sp_cache_clear(sp_cache **cp) { @@ -42,33 +43,31 @@ sp_cache_clear(sp_cache **cp) } } + void sp_cache_insert(sp_cache **cp, sp_head *sp) { sp_cache *c= *cp; + ulong v; if (! c) - c= new sp_cache(); - if (c) { - ulong v; - - pthread_mutex_lock(&Cversion_lock); // LOCK - v= Cversion; - pthread_mutex_unlock(&Cversion_lock); // UNLOCK + if (!(c= new sp_cache())) + return; // End of memory error + } - if (c->version < v) - { - if (*cp) - c->remove_all(); - c->version= v; - } - c->insert(sp); - if (*cp == NULL) - *cp= c; + v= Cversion; /* No need to lock when reading long variable */ + if (c->version < v) + { + if (*cp) + c->remove_all(); + c->version= v; } + c->insert(sp); + *cp= c; // Update *cp if it was NULL } + sp_head * sp_cache_lookup(sp_cache **cp, sp_name *name) { @@ -78,10 +77,8 @@ sp_cache_lookup(sp_cache **cp, sp_name *name) if (! c) return NULL; - pthread_mutex_lock(&Cversion_lock); // LOCK - v= Cversion; - pthread_mutex_unlock(&Cversion_lock); // UNLOCK - + + v= Cversion; /* No need to lock when reading long variable */ if (c->version < v) { c->remove_all(); @@ -91,6 +88,7 @@ sp_cache_lookup(sp_cache **cp, sp_name *name) return c->lookup(name->m_qname.str, name->m_qname.length); } + bool sp_cache_remove(sp_cache **cp, sp_name *name) { @@ -114,14 +112,14 @@ sp_cache_remove(sp_cache **cp, sp_name *name) return found; } + void sp_cache_invalidate() { - pthread_mutex_lock(&Cversion_lock); // LOCK - Cversion++; - pthread_mutex_unlock(&Cversion_lock); // UNLOCK + thread_safe_increment(Cversion, &Cversion_lock); // UNLOCK } + static byte * hash_get_key_for_sp_head(const byte *ptr, uint *plen, my_bool first) @@ -132,6 +130,7 @@ hash_get_key_for_sp_head(const byte *ptr, uint *plen, return (byte*) sp->m_qname.str; } + static void hash_free_sp_head(void *p) { @@ -140,16 +139,19 @@ hash_free_sp_head(void *p) delete sp; } + sp_cache::sp_cache() { init(); } + sp_cache::~sp_cache() { hash_free(&m_hashtable); } + void sp_cache::init() { @@ -158,6 +160,7 @@ sp_cache::init() version= 0; } + void sp_cache::cleanup() { |