~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/cache.h

  • Committer: Andrew Hutchings
  • Date: 2011-02-01 10:23:22 UTC
  • mto: (2136.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2137.
  • Revision ID: andrew@linuxjedi.co.uk-20110201102322-oxztcyrjzg3c7yta
Fix counters cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#pragma once
 
21
#ifndef DRIZZLED_DEFINITION_CACHE_H
 
22
#define DRIZZLED_DEFINITION_CACHE_H
22
23
 
23
 
#include <drizzled/table/instance.h>
 
24
#include "drizzled/table/instance.h"
24
25
 
25
26
namespace drizzled {
 
27
 
 
28
namespace generator {
 
29
class TableDefinitionCache;
 
30
}
 
31
 
26
32
namespace definition {
27
33
 
28
34
class Cache
29
35
{
30
36
public:
31
 
  static size_t size()
32
 
  {
33
 
    // no lock?
 
37
  static inline Cache &singleton()
 
38
  {
 
39
    static Cache open_cache;
 
40
 
 
41
    return open_cache;
 
42
  }
 
43
 
 
44
  size_t size() const
 
45
  {
34
46
    return cache.size();
35
47
  }
36
48
 
37
 
  static void rehash(size_t arg)
 
49
  void rehash(size_t arg)
38
50
  {
39
 
    // no lock?
40
51
    cache.rehash(arg);
41
52
  }
42
53
 
43
 
  static table::instance::Shared::shared_ptr find(const identifier::Table::Key&);
44
 
  static void erase(const identifier::Table::Key&);
45
 
  static bool insert(const identifier::Table::Key&, table::instance::Shared::shared_ptr);
 
54
  table::instance::Shared::shared_ptr find(const identifier::Table::Key &identifier);
 
55
  void erase(const identifier::Table::Key &identifier);
 
56
  bool insert(const identifier::Table::Key &identifier, table::instance::Shared::shared_ptr share);
 
57
 
 
58
protected:
 
59
  friend class drizzled::generator::TableDefinitionCache;
 
60
 
 
61
  void CopyFrom(table::instance::Shared::vector &vector);
 
62
 
46
63
private:
47
 
  static void CopyFrom(table::instance::Shared::vector&);
48
 
 
49
64
  typedef boost::unordered_map< identifier::Table::Key, table::instance::Shared::shared_ptr> Map;
50
65
 
51
 
  static Map cache;
52
 
  static boost::mutex _mutex;
53
 
 
54
 
  friend class generator::TableDefinitionCache;
 
66
  Map cache;
 
67
  boost::mutex _mutex;
55
68
};
56
69
 
57
70
} /* namespace definition */
58
71
} /* namespace drizzled */
59
72
 
 
73
#endif /* DRIZZLED_DEFINITION_CACHE_H */