21
21
#include "config.h"
23
#include <boost/bind.hpp>
24
#include <boost/thread/mutex.hpp>
25
#include <boost/thread/shared_mutex.hpp>
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"
31
#include "drizzled/table/instance.h"
26
#include "drizzled/definition/table.h"
33
28
namespace drizzled {
35
30
namespace definition {
37
table::instance::Shared::shared_ptr Cache::find(const identifier::Table::Key &key)
32
TableSharePtr Cache::find(const TableIdentifier &identifier)
39
boost::mutex::scoped_lock scopedLock(_mutex);
34
//safe_mutex_assert_owner(LOCK_open.native_handle);
41
Map::iterator iter= cache.find(key);
36
CacheMap::iterator iter= cache.find(identifier.getKey());
42
37
if (iter != cache.end())
44
39
return (*iter).second;
47
return table::instance::Shared::shared_ptr();
42
return TableSharePtr();
50
void Cache::erase(const identifier::Table::Key &key)
45
void Cache::erase(const TableIdentifier &identifier)
52
boost::mutex::scoped_lock scopedLock(_mutex);
47
//safe_mutex_assert_owner(LOCK_open.native_handle);
49
cache.erase(identifier.getKey());
57
bool Cache::insert(const identifier::Table::Key &key, table::instance::Shared::shared_ptr share)
52
bool Cache::insert(const TableIdentifier &identifier, TableSharePtr share)
59
boost::mutex::scoped_lock scopedLock(_mutex);
60
std::pair<Map::iterator, bool> ret=
61
cache.insert(std::make_pair(key, share));
54
std::pair<CacheMap::iterator, bool> ret=
55
cache.insert(std::make_pair(identifier.getKey(), share));
66
void Cache::CopyFrom(drizzled::table::instance::Shared::vector &vector)
68
boost::mutex::scoped_lock scopedLock(_mutex);
70
vector.reserve(definition::Cache::singleton().size());
72
std::transform(cache.begin(),
74
std::back_inserter(vector),
75
boost::bind(&Map::value_type::second, _1) );
76
assert(vector.size() == cache.size());
79
60
} /* namespace definition */
80
61
} /* namespace drizzled */