diff options
author | unknown <monty@mysql.com> | 2005-08-11 15:58:15 +0300 |
---|---|---|
committer | unknown <monty@mysql.com> | 2005-08-11 15:58:15 +0300 |
commit | d83f690851498c33f63a825ecd41dc73f3a8e73d (patch) | |
tree | 7d0b6e81295c86daf6c699dd29e763b6858d3b29 /sql/sp_cache.cc | |
parent | c4228519a663869ab3ab3d969890e4c6f5831e0f (diff) | |
download | mariadb-git-d83f690851498c33f63a825ecd41dc73f3a8e73d.tar.gz |
Cleanups during review of new code
mysql-test/t/sp.test:
Use --disable_parsing instead of comments
sql/lock.cc:
Remove compiler warning
sql/mysqld.cc:
Always send valid flag argument to reload_acl_and_cache()
sql/sp_cache.cc:
Simple optimization
Don't use mutex to read 'long' variable
Indentation fixes
sql/sp_head.cc:
Fix comments to use /* */
Set proc_info to 0 after close_thread_tables()
sql/sql_base.cc:
remove not needed test
sql/sql_parse.cc:
Always send valid flag argument to reload_acl_and_cache()
Fixed indentation
Ensure we get an error if reset_master() fails.
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() { |