00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
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());
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
00083 if (table == getTable())
00084 {
00085 setTable(getTable()->getNext());
00086 if (table == getTable())
00087 setTable(NULL);
00088 }
00089 }
00090
00091
00092
00093 void UnusedTables::relink(Concurrent *table)
00094 {
00095 if (table != getTable())
00096 {
00097 table->unlink();
00098
00099 table->setNext(getTable());
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 }
00114 }