Drizzled Public API Documentation

cache.h

00001 /* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2010 Brian Aker
00005  *  Copyright (C) 2010 Sun Microsystems, Inc.
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020  */
00021 
00022 #pragma once
00023 
00024 #include <boost/unordered_map.hpp>
00025 #include <drizzled/identifier.h>
00026 
00027 namespace drizzled {
00028 
00029 class Session;
00030 
00031 namespace table {
00032 
00033 namespace instance {
00034 class Shared;
00035 } 
00036 
00037 class Concurrent;
00038 
00039 typedef boost::unordered_multimap< identifier::Table::Key, Concurrent *> CacheMap;
00040 typedef std::pair< CacheMap::const_iterator, CacheMap::const_iterator > CacheRange;
00041 
00042 class Cache 
00043 {
00044   CacheMap cache;
00045 
00046 public:
00047   static inline Cache &singleton()
00048   {
00049     static Cache open_cache;
00050 
00051     return open_cache;
00052   }
00053 
00054   CacheMap &getCache()
00055   {
00056     return cache;
00057   }
00058 
00059   void rehash(size_t arg)
00060   {
00061     cache.rehash(arg);
00062   }
00063 
00064   bool areTablesUsed(Table *table, bool wait_for_name_lock);
00065   void removeSchema(const identifier::Schema &schema_identifier);
00066   bool removeTable(Session *session, identifier::Table &identifier, uint32_t flags);
00067   void release(table::instance::Shared *share);
00068   bool insert(table::Concurrent *arg);
00069 
00070   boost::mutex &mutex()
00071   {
00072     return _mutex;
00073   }
00074 
00075 private:
00076   boost::mutex _mutex;
00077 };
00078 
00079 CacheMap &getCache(void);
00080 void remove_table(table::Concurrent *arg);
00081 
00082 } /* namepsace table */
00083 } /* namepsace drizzled */
00084