1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
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.
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.
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
23
#include <sys/types.h>
28
#include "drizzled/identifier.h"
29
#include "drizzled/sql_base.h"
30
#include "drizzled/set_var.h"
32
#include "drizzled/table/unused.h"
37
extern uint64_t table_cache_size;
42
UnusedTables &getUnused(void)
44
static UnusedTables unused_tables;
49
void UnusedTables::cull()
51
/* Free cache if too big */
52
while (cached_open_tables() > table_cache_size && getTable())
53
remove_table(getTable());
56
void UnusedTables::cullByVersion()
58
while (getTable() && not getTable()->getShare()->getVersion())
59
remove_table(getTable());
62
void UnusedTables::link(Concurrent *table)
66
table->setNext(getTable()); /* Link in last */
67
table->setPrev(getTable()->getPrev());
68
getTable()->setPrev(table);
69
table->getPrev()->setNext(table);
73
table->setPrev(setTable(table));
74
table->setNext(table->getPrev());
75
assert(table->getNext() == table && table->getPrev() == table);
80
void UnusedTables::unlink(Concurrent *table)
84
/* Unlink the table from "unused_tables" list. */
85
if (table == getTable())
87
setTable(getTable()->getNext()); // Remove from link
88
if (table == getTable())
93
/* move table first in unused links */
95
void UnusedTables::relink(Concurrent *table)
97
if (table != getTable())
101
table->setNext(getTable()); /* Link in unused tables */
102
table->setPrev(getTable()->getPrev());
103
getTable()->getPrev()->setNext(table);
104
getTable()->setPrev(table);
109
void UnusedTables::clear()
112
remove_table(getTable());
115
} /* namespace table */
116
} /* namespace drizzled */