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
00032 #include <drizzled/table/unused.h>
00033
00034 namespace drizzled
00035 {
00036
00037 extern uint64_t table_cache_size;
00038
00039 namespace table
00040 {
00041
00042 UnusedTables &getUnused(void)
00043 {
00044 static UnusedTables unused_tables;
00045
00046 return unused_tables;
00047 }
00048
00049 void UnusedTables::cull()
00050 {
00051
00052 while (cached_open_tables() > table_cache_size && getTable())
00053 remove_table(getTable());
00054 }
00055
00056 void UnusedTables::cullByVersion()
00057 {
00058 while (getTable() && not getTable()->getShare()->getVersion())
00059 remove_table(getTable());
00060 }
00061
00062 void UnusedTables::link(Concurrent *table)
00063 {
00064 if (getTable())
00065 {
00066 table->setNext(getTable());
00067 table->setPrev(getTable()->getPrev());
00068 getTable()->setPrev(table);
00069 table->getPrev()->setNext(table);
00070 }
00071 else
00072 {
00073 table->setPrev(setTable(table));
00074 table->setNext(table->getPrev());
00075 assert(table->getNext() == table && table->getPrev() == table);
00076 }
00077 }
00078
00079
00080 void UnusedTables::unlink(Concurrent *table)
00081 {
00082 table->unlink();
00083
00084
00085 if (table == getTable())
00086 {
00087 setTable(getTable()->getNext());
00088 if (table == getTable())
00089 setTable(NULL);
00090 }
00091 }
00092
00093
00094
00095 void UnusedTables::relink(Concurrent *table)
00096 {
00097 if (table != getTable())
00098 {
00099 table->unlink();
00100
00101 table->setNext(getTable());
00102 table->setPrev(getTable()->getPrev());
00103 getTable()->getPrev()->setNext(table);
00104 getTable()->setPrev(table);
00105 setTable(table);
00106 }
00107 }
00108
00109 void UnusedTables::clear()
00110 {
00111 while (getTable())
00112 remove_table(getTable());
00113 }
00114
00115 }
00116 }