~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/cache.cc

  • Committer: Brian Aker
  • Date: 2010-11-06 15:43:10 UTC
  • mfrom: (1908.1.1 merge)
  • Revision ID: brian@tangent.org-20101106154310-g1jpjzwbc53pfc4f
Filesort encapsulation, plus modification to copy contructor

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
#include "config.h"
22
22
 
23
 
#include <boost/bind.hpp>
24
 
#include <boost/thread/mutex.hpp>
25
 
#include <boost/thread/shared_mutex.hpp>
26
 
 
 
23
#include "drizzled/pthread_globals.h"
27
24
#include "drizzled/session.h"
28
25
#include "drizzled/identifier/table.h"
29
 
#include "drizzled/definition/cache.h"
30
26
#include "drizzled/definition/table.h"
31
27
 
32
28
namespace drizzled {
33
29
 
34
30
namespace definition {
35
31
 
36
 
TableShare::shared_ptr Cache::find(const TableIdentifier::Key &key)
 
32
TableSharePtr Cache::find(const TableIdentifier &identifier)
37
33
{
38
 
  boost::mutex::scoped_lock scopedLock(_mutex);
 
34
  //safe_mutex_assert_owner(LOCK_open.native_handle);
39
35
 
40
 
  Map::iterator iter= cache.find(key);
 
36
  CacheMap::iterator iter= cache.find(identifier.getKey());
41
37
  if (iter != cache.end())
42
38
  {
43
39
    return (*iter).second;
44
40
  }
45
41
 
46
 
  return TableShare::shared_ptr();
 
42
  return TableSharePtr();
47
43
}
48
44
 
49
 
void Cache::erase(const TableIdentifier::Key &key)
 
45
void Cache::erase(const TableIdentifier &identifier)
50
46
{
51
 
  boost::mutex::scoped_lock scopedLock(_mutex);
 
47
  //safe_mutex_assert_owner(LOCK_open.native_handle);
52
48
  
53
 
  cache.erase(key);
 
49
  cache.erase(identifier.getKey());
54
50
}
55
51
 
56
 
bool Cache::insert(const TableIdentifier::Key &key, TableShare::shared_ptr share)
 
52
bool Cache::insert(const TableIdentifier &identifier, TableSharePtr share)
57
53
{
58
 
  boost::mutex::scoped_lock scopedLock(_mutex);
59
 
  std::pair<Map::iterator, bool> ret=
60
 
    cache.insert(std::make_pair(key, share));
 
54
  std::pair<CacheMap::iterator, bool> ret=
 
55
    cache.insert(std::make_pair(identifier.getKey(), share));
61
56
 
62
57
  return ret.second;
63
58
}
64
59
 
65
 
void Cache::CopyFrom(drizzled::TableShare::vector &vector)
66
 
{
67
 
  boost::mutex::scoped_lock scopedLock(_mutex);
68
 
 
69
 
  vector.reserve(definition::Cache::singleton().size());
70
 
 
71
 
  std::transform(cache.begin(),
72
 
                 cache.end(),
73
 
                 std::back_inserter(vector),
74
 
                 boost::bind(&Map::value_type::second, _1) );
75
 
  assert(vector.size() == cache.size());
76
 
}
77
 
 
78
60
} /* namespace definition */
79
61
} /* namespace drizzled */