~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/unused.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
32
#include <drizzled/table/unused.h>
 
33
 
 
34
namespace drizzled
 
35
{
 
36
 
 
37
extern uint64_t table_cache_size;
 
38
 
 
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
 
 
62
void UnusedTables::link(Concurrent *table)
 
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
 
 
80
void UnusedTables::unlink(Concurrent *table)
 
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
 
 
95
void UnusedTables::relink(Concurrent *table)
 
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
}
 
114
 
 
115
} /* namespace table */
 
116
} /* namespace drizzled */