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
21
#ifndef DRIZZLED_CATALOG_CACHE_H
22
#define DRIZZLED_CATALOG_CACHE_H
24
#include <boost/bind.hpp>
26
#include "drizzled/catalog.h"
27
#include "drizzled/plugin/catalog.h"
28
#include "drizzled/identifier.h"
30
#include <boost/unordered_map.hpp>
31
#include <boost/thread/mutex.hpp>
44
} //namespace generator
56
static inline Cache &singleton()
58
static Cache open_cache;
68
void rehash(size_t arg)
73
Instance::shared_ptr find(const identifier::Catalog &identifier, catalog::error_t &error);
74
bool exist(const identifier::Catalog &identifier);
75
bool erase(const identifier::Catalog &identifier, catalog::error_t &error);
76
bool insert(const identifier::Catalog &identifier, Instance::shared_ptr instance, catalog::error_t &error);
77
bool lock(const identifier::Catalog &identifier, catalog::error_t &error);
78
bool unlock(const identifier::Catalog &identifier, catalog::error_t &error);
80
friend class drizzled::generator::catalog::Cache;
81
friend class drizzled::plugin::Catalog;
82
friend class drizzled::catalog::lock::Erase;
83
friend class drizzled::catalog::lock::Create;
85
void copy(catalog::Instance::vector &vector);
87
typedef boost::unordered_map< identifier::Catalog, catalog::Instance::shared_ptr> unordered_map;
99
const identifier::Catalog &identifier;
100
catalog::error_t error;
103
Erase(const identifier::Catalog &identifier_arg) :
105
identifier(identifier_arg)
119
if (not catalog::Cache::singleton().unlock(identifier, error))
121
catalog::error(error, identifier);
130
// We insert a lock into the cache, if this fails we bail.
131
if (not catalog::Cache::singleton().lock(identifier, error))
145
const identifier::Catalog &identifier;
146
catalog::error_t error;
149
Create(const identifier::Catalog &identifier_arg) :
151
identifier(identifier_arg)
165
if (not catalog::Cache::singleton().unlock(identifier, error))
167
catalog::error(error, identifier);
177
// We insert a lock into the cache, if this fails we bail.
178
if (not catalog::Cache::singleton().lock(identifier, error))
188
} /* namespace lock */
189
} /* namespace catalog */
190
} /* namespace drizzled */
192
#endif /* DRIZZLED_CATALOG_CACHE_H */