summaryrefslogtreecommitdiff
path: root/sql/sp_cache.cc
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2005-08-11 16:43:22 +0300
committerunknown <monty@mysql.com>2005-08-11 16:43:22 +0300
commitd620954a67fa4518eebda00a07fef846014d1ca7 (patch)
tree34d11d26935b8393579432cab64f17d9842ac38c /sql/sp_cache.cc
parent98da6d5ffbaf00dfc9f2b3d18bbda665cf3fd67e (diff)
parentd83f690851498c33f63a825ecd41dc73f3a8e73d (diff)
downloadmariadb-git-d620954a67fa4518eebda00a07fef846014d1ca7.tar.gz
Merge bk-internal.mysql.com:/home/bk/mysql-5.0
into mysql.com:/home/my/mysql-5.0 mysql-test/t/sp.test: Auto merged sql/sp_head.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_parse.cc: Auto merged sql/sp_cache.cc: manual merge
Diffstat (limited to 'sql/sp_cache.cc')
-rw-r--r--sql/sp_cache.cc54
1 files changed, 27 insertions, 27 deletions
diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc
index 68e8dbb3252..495f969eeac 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;
/*
@@ -86,9 +86,11 @@ void sp_cache_init()
/*
Clear the cache *cp and set *cp to NULL.
+
SYNOPSIS
sp_cache_clear()
- cp Pointer to cache to clear
+ cp Pointer to cache to clear
+
NOTE
This function doesn't invalidate other caches.
*/
@@ -96,6 +98,7 @@ void sp_cache_init()
void sp_cache_clear(sp_cache **cp)
{
sp_cache *c= *cp;
+
if (c)
{
delete c;
@@ -109,8 +112,8 @@ void sp_cache_clear(sp_cache **cp)
SYNOPSIS
sp_cache_insert()
- cp The cache to put routine into
- sp Routine to insert.
+ cp The cache to put routine into
+ sp Routine to insert.
TODO: Perhaps it will be more straightforward if in case we returned an
error from this function when we couldn't allocate sp_cache. (right
@@ -120,22 +123,19 @@ void sp_cache_clear(sp_cache **cp)
void sp_cache_insert(sp_cache **cp, sp_head *sp)
{
- sp_cache *c= *cp;
+ sp_cache *c;
+ ulong v;
- if (!c && (c= new sp_cache()))
- {
- pthread_mutex_lock(&Cversion_lock); // LOCK
- c->version= Cversion;
- pthread_mutex_unlock(&Cversion_lock); // UNLOCK
- }
- if (c)
+ if (!(c= *cp))
{
- DBUG_PRINT("info",("sp_cache: inserting: %*s", sp->m_qname.length,
- sp->m_qname.str));
- c->insert(sp);
- if (*cp == NULL)
- *cp= c;
+ if (!(c= new sp_cache()))
+ return; // End of memory error
+ c->version= Cversion; // No need to lock when reading long variable
}
+ DBUG_PRINT("info",("sp_cache: inserting: %*s", sp->m_qname.length,
+ sp->m_qname.str));
+ c->insert(sp);
+ *cp= c; // Update *cp if it was NULL
}
@@ -158,7 +158,7 @@ void sp_cache_insert(sp_cache **cp, sp_head *sp)
sp_head *sp_cache_lookup(sp_cache **cp, sp_name *name)
{
sp_cache *c= *cp;
- if (!c)
+ if (! c)
return NULL;
return c->lookup(name->m_qname.str, name->m_qname.length);
}
@@ -178,9 +178,7 @@ sp_head *sp_cache_lookup(sp_cache **cp, sp_name *name)
void sp_cache_invalidate()
{
DBUG_PRINT("info",("sp_cache: invalidating"));
- pthread_mutex_lock(&Cversion_lock); // LOCK
- Cversion++;
- pthread_mutex_unlock(&Cversion_lock); // UNLOCK
+ thread_safe_increment(Cversion, &Cversion_lock);
}
@@ -202,9 +200,7 @@ void sp_cache_flush_obsolete(sp_cache **cp)
if (c)
{
ulong v;
- 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)
{
DBUG_PRINT("info",("sp_cache: deleting all functions"));
@@ -215,20 +211,20 @@ void sp_cache_flush_obsolete(sp_cache **cp)
}
}
+
/*************************************************************************
Internal functions
*************************************************************************/
-static byte *
-hash_get_key_for_sp_head(const byte *ptr, uint *plen,
+static byte *hash_get_key_for_sp_head(const byte *ptr, uint *plen,
my_bool first)
{
sp_head *sp= (sp_head *)ptr;
-
*plen= sp->m_qname.length;
return (byte*) sp->m_qname.str;
}
+
static void
hash_free_sp_head(void *p)
{
@@ -236,16 +232,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()
{
@@ -254,6 +253,7 @@ sp_cache::init()
version= 0;
}
+
void
sp_cache::cleanup()
{