mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 05:22:25 +01:00
7e8cc90a8b
Need a sp_cache_remove() function with implicit name lookup to make the WL task to work. It's a cleaner and more convenient interface anyway... sql/sp.cc: Modified sp_cache_remove() function calls; just remove by name. sql/sp_cache.cc: Modified sp_cache_remove() function. Get name and lookup/remove, return the removed entry, if any. sql/sp_cache.h: Modified sp_cache_remove() function. Get name and lookup/remove, return the removed entry, if any.
148 lines
2.6 KiB
C++
148 lines
2.6 KiB
C++
/* Copyright (C) 2002 MySQL AB
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
#ifdef __GNUC__
|
|
#pragma implementation
|
|
#endif
|
|
|
|
#include "mysql_priv.h"
|
|
#include "sp_cache.h"
|
|
#include "sp_head.h"
|
|
|
|
static pthread_mutex_t Cversion_lock;
|
|
static ulong Cversion = 0;
|
|
|
|
void
|
|
sp_cache_init()
|
|
{
|
|
pthread_mutex_init(&Cversion_lock, MY_MUTEX_INIT_FAST);
|
|
}
|
|
|
|
void
|
|
sp_cache_clear(sp_cache **cp)
|
|
{
|
|
sp_cache *c= *cp;
|
|
|
|
if (c)
|
|
{
|
|
delete c;
|
|
*cp= NULL;
|
|
}
|
|
}
|
|
|
|
void
|
|
sp_cache_insert(sp_cache **cp, sp_head *sp)
|
|
{
|
|
sp_cache *c= *cp;
|
|
|
|
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->version < v)
|
|
{
|
|
if (*cp)
|
|
c->remove_all();
|
|
c->version= v;
|
|
}
|
|
c->insert(sp);
|
|
if (*cp == NULL)
|
|
*cp= c;
|
|
}
|
|
}
|
|
|
|
sp_head *
|
|
sp_cache_lookup(sp_cache **cp, char *name, uint namelen)
|
|
{
|
|
ulong v;
|
|
sp_cache *c= *cp;
|
|
|
|
if (! c)
|
|
return NULL;
|
|
|
|
pthread_mutex_lock(&Cversion_lock); // LOCK
|
|
v= Cversion;
|
|
pthread_mutex_unlock(&Cversion_lock); // UNLOCK
|
|
|
|
if (c->version < v)
|
|
{
|
|
c->remove_all();
|
|
c->version= v;
|
|
return NULL;
|
|
}
|
|
return c->lookup(name, namelen);
|
|
}
|
|
|
|
sp_head *
|
|
sp_cache_remove(sp_cache **cp, char *name, uint namelen)
|
|
{
|
|
sp_cache *c= *cp;
|
|
sp_head *sp= NULL;
|
|
|
|
if (c)
|
|
{
|
|
ulong v;
|
|
|
|
pthread_mutex_lock(&Cversion_lock); // LOCK
|
|
v= Cversion++;
|
|
pthread_mutex_unlock(&Cversion_lock); // UNLOCK
|
|
|
|
if (c->version < v)
|
|
c->remove_all();
|
|
else
|
|
sp= c->remove(name, namelen);
|
|
c->version= v+1;
|
|
}
|
|
return sp;
|
|
}
|
|
|
|
|
|
static byte *
|
|
hash_get_key_for_sp_head(const byte *ptr, uint *plen,
|
|
my_bool first)
|
|
{
|
|
return ((sp_head*)ptr)->name(plen);
|
|
}
|
|
|
|
sp_cache::sp_cache()
|
|
{
|
|
init();
|
|
}
|
|
|
|
sp_cache::~sp_cache()
|
|
{
|
|
hash_free(&m_hashtable);
|
|
}
|
|
|
|
void
|
|
sp_cache::init()
|
|
{
|
|
hash_init(&m_hashtable, system_charset_info, 0, 0, 0,
|
|
hash_get_key_for_sp_head, 0, 0);
|
|
version= 0;
|
|
}
|
|
|
|
void
|
|
sp_cache::cleanup()
|
|
{
|
|
hash_free(&m_hashtable);
|
|
}
|