~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/unused.cc

  • Committer: devananda
  • Date: 2009-07-01 17:38:47 UTC
  • mto: (1093.1.7 captain)
  • mto: This revision was merged to the branch mainline in revision 1095.
  • Revision ID: devananda.vdv@gmail.com-20090701173847-3n3mbtessg5ff35e
refactored function/benchmark into plugin/benchmark

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/table.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
 
namespace table
38
 
{
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 */
50
 
  while (cached_open_tables() > table_cache_size && getTable())
51
 
    remove_table(getTable());
52
 
}
53
 
 
54
 
void UnusedTables::cullByVersion()
55
 
{
56
 
  while (getTable() && not getTable()->getShare()->getVersion())
57
 
    remove_table(getTable());
58
 
}
59
 
 
60
 
void 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
 
 
78
 
void 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
 
 
93
 
void 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
 
 
107
 
void UnusedTables::clear()
108
 
{
109
 
  while (getTable())
110
 
    remove_table(getTable());
111
 
}
112
 
 
113
 
} /* namespace table */
114
 
} /* namespace drizzled */