Drizzled Public API Documentation

unused.cc
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  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <sys/types.h>
00024 #include <sys/stat.h>
00025 #include <fcntl.h>
00026 
00027 
00028 #include <drizzled/identifier.h>
00029 #include <drizzled/sql_base.h>
00030 #include <drizzled/set_var.h>
00031 #include <drizzled/table/cache.h>
00032 #include <drizzled/table/unused.h>
00033 
00034 namespace drizzled {
00035 
00036 extern uint64_t table_cache_size;
00037 
00038 namespace table {
00039 
00040 UnusedTables &getUnused(void)
00041 {
00042   static UnusedTables unused_tables;
00043 
00044   return unused_tables;
00045 }
00046 
00047 void UnusedTables::cull()
00048 {
00049   /* Free cache if too big */
00050   while (table::getCache().size() > table_cache_size && getTable())
00051     remove_table(getTable());
00052 }
00053 
00054 void UnusedTables::cullByVersion()
00055 {
00056   while (getTable() && not getTable()->getShare()->getVersion())
00057     remove_table(getTable());
00058 }
00059 
00060 void UnusedTables::link(Concurrent *table)
00061 {
00062   if (getTable())
00063   {
00064     table->setNext(getTable());   /* Link in last */
00065     table->setPrev(getTable()->getPrev());
00066     getTable()->setPrev(table);
00067     table->getPrev()->setNext(table);
00068   }
00069   else
00070   {
00071     table->setPrev(setTable(table));
00072     table->setNext(table->getPrev());
00073     assert(table->getNext() == table && table->getPrev() == table);
00074   }
00075 }
00076 
00077 
00078 void UnusedTables::unlink(Concurrent *table)
00079 {
00080   table->unlink();
00081 
00082   /* Unlink the table from "unused_tables" list. */
00083   if (table == getTable())
00084   {  // First unused
00085     setTable(getTable()->getNext()); // Remove from link
00086     if (table == getTable())
00087       setTable(NULL);
00088   }
00089 }
00090 
00091 /* move table first in unused links */
00092 
00093 void UnusedTables::relink(Concurrent *table)
00094 {
00095   if (table != getTable())
00096   {
00097     table->unlink();
00098 
00099     table->setNext(getTable());     /* Link in unused tables */
00100     table->setPrev(getTable()->getPrev());
00101     getTable()->getPrev()->setNext(table);
00102     getTable()->setPrev(table);
00103     setTable(table);
00104   }
00105 }
00106 
00107 void UnusedTables::clear()
00108 {
00109   while (getTable())
00110     remove_table(getTable());
00111 }
00112 
00113 } /* namespace table */
00114 } /* namespace drizzled */