~drizzle-trunk/drizzle/development

1877.2.2 by Brian Aker
Move unused out to its own class.
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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
1877.2.2 by Brian Aker
Move unused out to its own class.
22
23
#include <sys/types.h>
24
#include <sys/stat.h>
25
#include <fcntl.h>
26
27
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
28
#include <drizzled/identifier.h>
29
#include <drizzled/sql_base.h>
30
#include <drizzled/set_var.h>
2272.1.1 by Olaf van der Spek
Refactor includes
31
#include <drizzled/table/cache.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
32
#include <drizzled/table/unused.h>
1877.2.2 by Brian Aker
Move unused out to its own class.
33
2272.1.1 by Olaf van der Spek
Refactor includes
34
namespace drizzled {
1877.2.2 by Brian Aker
Move unused out to its own class.
35
2148.7.12 by Brian Aker
Merge in header fixes.
36
extern uint64_t table_cache_size;
37
2272.1.1 by Olaf van der Spek
Refactor includes
38
namespace table {
1877.2.2 by Brian Aker
Move unused out to its own class.
39
40
UnusedTables &getUnused(void)
41
{
42
  static UnusedTables unused_tables;
43
44
  return unused_tables;
45
}
46
47
void UnusedTables::cull()
48
{
49
  /* Free cache if too big */
2318.2.16 by Olaf van der Spek
Refactor
50
  while (table::getCache().size() > table_cache_size && getTable())
1877.2.2 by Brian Aker
Move unused out to its own class.
51
    remove_table(getTable());
52
}
53
54
void UnusedTables::cullByVersion()
55
{
56
  while (getTable() && not getTable()->getShare()->getVersion())
57
    remove_table(getTable());
58
}
59
1877.2.3 by Brian Aker
Move unused under table
60
void UnusedTables::link(Concurrent *table)
1877.2.2 by Brian Aker
Move unused out to its own class.
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
1877.2.3 by Brian Aker
Move unused under table
78
void UnusedTables::unlink(Concurrent *table)
1877.2.2 by Brian Aker
Move unused out to its own class.
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
1877.2.3 by Brian Aker
Move unused under table
93
void UnusedTables::relink(Concurrent *table)
1877.2.2 by Brian Aker
Move unused out to its own class.
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
107
void UnusedTables::clear()
108
{
109
  while (getTable())
110
    remove_table(getTable());
111
}
1877.2.3 by Brian Aker
Move unused under table
112
113
} /* namespace table */
1877.2.2 by Brian Aker
Move unused out to its own class.
114
} /* namespace drizzled */