~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/cache.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

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