18
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
22
#include <drizzled/pthread_globals.h>
24
#include "drizzled/message/cache.h"
23
#include <drizzled/message/cache.h>
24
#include <drizzled/util/find_ptr.h>
26
26
namespace drizzled {
28
27
namespace message {
30
29
table::shared_ptr Cache::find(const identifier::Table &identifier)
32
boost_unique_lock_t scoped_lock(_access);
34
Map::iterator iter= cache.find(identifier.getKey());
35
if (iter != cache.end())
37
return (*iter).second;
31
boost::mutex::scoped_lock scoped_lock(_access);
32
if (Map::mapped_type* ptr= find_ptr(cache, identifier.getKey()))
40
34
return table::shared_ptr();
43
37
void Cache::erase(const identifier::Table &identifier)
45
boost_unique_lock_t scoped_lock(_access);
39
boost::mutex::scoped_lock scoped_lock(_access);
47
40
cache.erase(identifier.getKey());
50
43
bool Cache::insert(const identifier::Table &identifier, table::shared_ptr share)
52
boost_unique_lock_t scoped_lock(_access);
54
std::pair<Map::iterator, bool> ret=
55
cache.insert(std::make_pair(identifier.getKey(), share));
45
boost::mutex::scoped_lock scoped_lock(_access);
46
return cache.insert(std::make_pair(identifier.getKey(), share)).second;
60
49
bool Cache::insert(const identifier::Table &identifier, drizzled::message::Table &message)
62
boost_unique_lock_t scoped_lock(_access);
64
table::shared_ptr share;
65
share.reset(new message::Table(message));
67
std::pair<Map::iterator, bool> ret=
68
cache.insert(std::make_pair(identifier.getKey(), share));
51
return insert(identifier, table::shared_ptr(new message::Table(message)));
73
} /* namespace definition */
74
} /* namespace drizzled */
54
} // namespace message
55
} // namespace drizzled