drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
unused.cc
1/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3 *
4 * Copyright (C) 2010 Brian Aker
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <config.h>
22
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <fcntl.h>
26
27
28#include <drizzled/identifier.h>
29#include <drizzled/sql_base.h>
30#include <drizzled/set_var.h>
31#include <drizzled/table/cache.h>
32#include <drizzled/table/unused.h>
33
34namespace drizzled {
35
36extern uint64_t table_cache_size;
37
38namespace table {
39
40UnusedTables &getUnused(void)
41{
42 static UnusedTables unused_tables;
43
44 return unused_tables;
45}
46
47void UnusedTables::cull()
48{
49 /* Free cache if too big */
50 while (table::getCache().size() > table_cache_size && getTable())
51 remove_table(getTable());
52}
53
54void UnusedTables::cullByVersion()
55{
56 while (getTable() && not getTable()->getShare()->getVersion())
57 remove_table(getTable());
58}
59
60void UnusedTables::link(Concurrent *table)
61{
62 if (getTable())
63 {
64 table->setNext(getTable()); /* Link in last */
65 table->setPrev(getTable()->getPrev());
66 getTable()->setPrev(table);
67 table->getPrev()->setNext(table);
68 }
69 else
70 {
71 table->setPrev(setTable(table));
72 table->setNext(table->getPrev());
73 assert(table->getNext() == table && table->getPrev() == table);
74 }
75}
76
77
78void UnusedTables::unlink(Concurrent *table)
79{
80 table->unlink();
81
82 /* Unlink the table from "unused_tables" list. */
83 if (table == getTable())
84 { // First unused
85 setTable(getTable()->getNext()); // Remove from link
86 if (table == getTable())
87 setTable(NULL);
88 }
89}
90
91/* move table first in unused links */
92
93void UnusedTables::relink(Concurrent *table)
94{
95 if (table != getTable())
96 {
97 table->unlink();
98
99 table->setNext(getTable()); /* Link in unused tables */
100 table->setPrev(getTable()->getPrev());
101 getTable()->getPrev()->setNext(table);
102 getTable()->setPrev(table);
103 setTable(table);
104 }
105}
106
107void UnusedTables::clear()
108{
109 while (getTable())
110 remove_table(getTable());
111}
112
113} /* namespace table */
114} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.