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> |
|
1877.2.2
by Brian Aker
Move unused out to its own class. |
31 |
|
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 |
|
34 |
namespace drizzled |
|
35 |
{
|
|
36 |
||
2148.7.12
by Brian Aker
Merge in header fixes. |
37 |
extern uint64_t table_cache_size; |
38 |
||
1877.2.2
by Brian Aker
Move unused out to its own class. |
39 |
namespace table |
40 |
{
|
|
41 |
||
42 |
UnusedTables &getUnused(void) |
|
43 |
{
|
|
44 |
static UnusedTables unused_tables; |
|
45 |
||
46 |
return unused_tables; |
|
47 |
}
|
|
48 |
||
49 |
void UnusedTables::cull() |
|
50 |
{
|
|
51 |
/* Free cache if too big */
|
|
52 |
while (cached_open_tables() > table_cache_size && getTable()) |
|
53 |
remove_table(getTable()); |
|
54 |
}
|
|
55 |
||
56 |
void UnusedTables::cullByVersion() |
|
57 |
{
|
|
58 |
while (getTable() && not getTable()->getShare()->getVersion()) |
|
59 |
remove_table(getTable()); |
|
60 |
}
|
|
61 |
||
1877.2.3
by Brian Aker
Move unused under table |
62 |
void UnusedTables::link(Concurrent *table) |
1877.2.2
by Brian Aker
Move unused out to its own class. |
63 |
{
|
64 |
if (getTable()) |
|
65 |
{
|
|
66 |
table->setNext(getTable()); /* Link in last */ |
|
67 |
table->setPrev(getTable()->getPrev()); |
|
68 |
getTable()->setPrev(table); |
|
69 |
table->getPrev()->setNext(table); |
|
70 |
}
|
|
71 |
else
|
|
72 |
{
|
|
73 |
table->setPrev(setTable(table)); |
|
74 |
table->setNext(table->getPrev()); |
|
75 |
assert(table->getNext() == table && table->getPrev() == table); |
|
76 |
}
|
|
77 |
}
|
|
78 |
||
79 |
||
1877.2.3
by Brian Aker
Move unused under table |
80 |
void UnusedTables::unlink(Concurrent *table) |
1877.2.2
by Brian Aker
Move unused out to its own class. |
81 |
{
|
82 |
table->unlink(); |
|
83 |
||
84 |
/* Unlink the table from "unused_tables" list. */
|
|
85 |
if (table == getTable()) |
|
86 |
{ // First unused |
|
87 |
setTable(getTable()->getNext()); // Remove from link |
|
88 |
if (table == getTable()) |
|
89 |
setTable(NULL); |
|
90 |
}
|
|
91 |
}
|
|
92 |
||
93 |
/* move table first in unused links */
|
|
94 |
||
1877.2.3
by Brian Aker
Move unused under table |
95 |
void UnusedTables::relink(Concurrent *table) |
1877.2.2
by Brian Aker
Move unused out to its own class. |
96 |
{
|
97 |
if (table != getTable()) |
|
98 |
{
|
|
99 |
table->unlink(); |
|
100 |
||
101 |
table->setNext(getTable()); /* Link in unused tables */ |
|
102 |
table->setPrev(getTable()->getPrev()); |
|
103 |
getTable()->getPrev()->setNext(table); |
|
104 |
getTable()->setPrev(table); |
|
105 |
setTable(table); |
|
106 |
}
|
|
107 |
}
|
|
108 |
||
109 |
void UnusedTables::clear() |
|
110 |
{
|
|
111 |
while (getTable()) |
|
112 |
remove_table(getTable()); |
|
113 |
}
|
|
1877.2.3
by Brian Aker
Move unused under table |
114 |
|
115 |
} /* namespace table */ |
|
1877.2.2
by Brian Aker
Move unused out to its own class. |
116 |
} /* namespace drizzled */ |