sp_cache.h 2.18 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/* -*- 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 */

#ifndef _SP_CACHE_H_
#define _SP_CACHE_H_

#ifdef __GNUC__
#pragma interface			/* gcc class implementation */
#endif

class sp_head;
26 27 28 29 30 31 32 33 34 35 36 37
class sp_cache;

/* Initialize the SP caching once at startup */
void sp_cache_init();

/* Clear the cache *cp and set *cp to NULL */
void sp_cache_clear(sp_cache **cp);

/* Insert an SP to cache. If 'cp' points to NULL, it's set to a new cache */
void sp_cache_insert(sp_cache **cp, sp_head *sp);

/* Lookup an SP in cache */
38
sp_head *sp_cache_lookup(sp_cache **cp, sp_name *name);
39

40
/* Remove an SP from cache. Returns true if something was removed */
41
bool sp_cache_remove(sp_cache **cp, sp_name *name);
42

43 44 45
/* Invalidate a cache */
void sp_cache_invalidate();

46 47 48 49 50 51

/*
 *
 * The cache class. Don't use this directly, use the C API above
 *
 */
52 53 54 55 56

class sp_cache
{
public:

57 58
  ulong version;

59 60 61 62 63 64 65 66 67 68 69 70 71
  sp_cache();

  ~sp_cache();

  void
  init();

  void
  cleanup();

  inline void
  insert(sp_head *sp)
  {
pem@mysql.telia.com's avatar
pem@mysql.telia.com committed
72
    my_hash_insert(&m_hashtable, (const byte *)sp);
73 74 75 76 77 78 79 80
  }

  inline sp_head *
  lookup(char *name, uint namelen)
  {
    return (sp_head *)hash_search(&m_hashtable, (const byte *)name, namelen);
  }

81
  inline bool
82
  remove(char *name, uint namelen)
83
  {
84 85 86
    sp_head *sp= lookup(name, namelen);

    if (sp)
87
    {
88
      hash_delete(&m_hashtable, (byte *)sp);
89 90 91
      return TRUE;
    }
    return FALSE;
92 93
  }

94 95 96 97 98 99 100
  inline void
  remove_all()
  {
    cleanup();
    init();
  }

101 102 103 104 105 106 107
private:

  HASH m_hashtable;

}; // class sp_cache

#endif /* _SP_CACHE_H_ */