~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to drizzled/catalog/cache.h

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
#include <boost/bind.hpp>
24
24
 
 
25
#include <drizzled/identifier.h>
25
26
#include <drizzled/error.h>
26
27
#include <drizzled/catalog.h>
27
28
#include <drizzled/plugin/catalog.h>
30
31
#include <boost/thread/mutex.hpp>
31
32
 
32
33
namespace drizzled {
33
 
 
34
 
namespace plugin {
35
 
class Catalog;
36
 
}
37
 
namespace generator {
38
 
namespace catalog {
39
 
class Cache;
40
 
class Instance;
41
 
 
42
 
} //namespace catalog
43
 
} //namespace generator
44
 
 
45
 
namespace catalog {
46
 
 
47
 
namespace lock {
48
 
class Create;
49
 
class Erase;
50
 
 
51
 
} //namespace lock
 
34
namespace catalog  {
52
35
 
53
36
class Cache
54
37
{
55
 
  static inline Cache &singleton()
56
 
  {
57
 
    static Cache open_cache;
58
 
 
59
 
    return open_cache;
60
 
  }
61
 
 
62
 
  size_t size() const
 
38
public:
 
39
  static size_t size()
63
40
  {
64
41
    return cache.size();
65
42
  }
66
43
 
67
 
  void rehash(size_t arg)
68
 
  {
69
 
    cache.rehash(arg);
70
 
  }
71
 
 
72
 
  Instance::shared_ptr find(const identifier::Catalog &identifier, drizzled::error_t &error);
73
 
  bool exist(const identifier::Catalog &identifier);
74
 
  bool erase(const identifier::Catalog &identifier, drizzled::error_t &error);
75
 
  bool insert(const identifier::Catalog &identifier, Instance::shared_ptr instance, drizzled::error_t &error);
76
 
  bool lock(const identifier::Catalog &identifier, drizzled::error_t &error);
77
 
  bool unlock(const identifier::Catalog &identifier, drizzled::error_t &error);
78
 
 
79
 
  friend class drizzled::generator::catalog::Cache;
80
 
  friend class drizzled::plugin::Catalog;
81
 
  friend class drizzled::catalog::lock::Erase;
82
 
  friend class drizzled::catalog::lock::Create;
83
 
 
84
 
  void copy(catalog::Instance::vector &vector);
85
 
 
86
 
  typedef boost::unordered_map< identifier::Catalog, catalog::Instance::shared_ptr> unordered_map;
87
 
 
88
 
  unordered_map cache;
89
 
  boost::mutex _mutex;
 
44
  static Instance::shared_ptr find(const identifier::Catalog&, error_t&);
 
45
  static bool exist(const identifier::Catalog&);
 
46
  static bool erase(const identifier::Catalog&, error_t&);
 
47
  static bool insert(const identifier::Catalog&, Instance::shared_ptr, error_t&);
 
48
  static bool lock(const identifier::Catalog&, error_t&);
 
49
  static bool unlock(const identifier::Catalog&, error_t&);
 
50
  static void copy(catalog::Instance::vector&);
 
51
 
 
52
  typedef boost::unordered_map<identifier::Catalog, catalog::Instance::shared_ptr> unordered_map;
 
53
 
 
54
  static unordered_map cache;
 
55
  static boost::mutex _mutex;
90
56
};
91
57
 
92
58
 
96
62
{
97
63
  bool _locked;
98
64
  const identifier::Catalog &identifier;
99
 
  drizzled::error_t error;
 
65
  error_t error;
100
66
 
101
67
public:
102
68
  Erase(const identifier::Catalog &identifier_arg) :
115
81
  {
116
82
    if (_locked)
117
83
    {
118
 
      if (not catalog::Cache::singleton().unlock(identifier, error))
 
84
      if (not catalog::Cache::unlock(identifier, error))
119
85
      {
120
86
        my_error(error, identifier);
121
87
        assert(0);
127
93
  void init()
128
94
  {
129
95
    // We insert a lock into the cache, if this fails we bail.
130
 
    if (not catalog::Cache::singleton().lock(identifier, error))
 
96
    if (not catalog::Cache::lock(identifier, error))
131
97
    {
132
98
      assert(0);
133
99
      return;
142
108
{
143
109
  bool _locked;
144
110
  const identifier::Catalog &identifier;
145
 
  drizzled::error_t error;
 
111
  error_t error;
146
112
 
147
113
public:
148
114
  Create(const identifier::Catalog &identifier_arg) :
161
127
  {
162
128
    if (_locked)
163
129
    {
164
 
      if (not catalog::Cache::singleton().unlock(identifier, error))
 
130
      if (not catalog::Cache::unlock(identifier, error))
165
131
      {
166
132
        my_error(error, identifier);
167
133
        assert(0);
174
140
  void init()
175
141
  {
176
142
    // We insert a lock into the cache, if this fails we bail.
177
 
    if (not catalog::Cache::singleton().lock(identifier, error))
 
143
    if (not catalog::Cache::lock(identifier, error))
178
144
    {
179
145
      my_error(error, identifier);
180
146
      return;