~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/cache.cc

  • Committer: Monty Taylor
  • Date: 2011-01-26 19:15:55 UTC
  • mto: This revision was merged to the branch mainline in revision 2126.
  • Revision ID: mordred@inaugust.com-20110126191555-nq5nnzyscvngsip2
Turns on -fvisibility=hidden by default. Symbols intended to be used by
plugins need to be marked with DRIZZLED_API.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include <config.h>
 
21
#include "config.h"
 
22
 
22
23
#include <drizzled/pthread_globals.h>
23
 
#include <drizzled/message/cache.h>
24
 
#include <drizzled/util/find_ptr.h>
 
24
#include "drizzled/message/cache.h"
25
25
 
26
26
namespace drizzled {
 
27
 
27
28
namespace message {
28
29
 
29
30
table::shared_ptr Cache::find(const identifier::Table &identifier)
30
31
{
31
 
  boost::mutex::scoped_lock scoped_lock(_access);
32
 
  if (Map::mapped_type* ptr= find_ptr(cache, identifier.getKey()))
33
 
    return *ptr;
 
32
  boost_unique_lock_t scoped_lock(_access);
 
33
 
 
34
  Map::iterator iter= cache.find(identifier.getKey());
 
35
  if (iter != cache.end())
 
36
  {
 
37
    return (*iter).second;
 
38
  }
 
39
 
34
40
  return table::shared_ptr();
35
41
}
36
42
 
37
43
void Cache::erase(const identifier::Table &identifier)
38
44
{
39
 
  boost::mutex::scoped_lock scoped_lock(_access);
 
45
  boost_unique_lock_t scoped_lock(_access);
 
46
  
40
47
  cache.erase(identifier.getKey());
41
48
}
42
49
 
43
50
bool Cache::insert(const identifier::Table &identifier, table::shared_ptr share)
44
51
{
45
 
  boost::mutex::scoped_lock scoped_lock(_access);
46
 
  return cache.insert(std::make_pair(identifier.getKey(), share)).second;
 
52
  boost_unique_lock_t scoped_lock(_access);
 
53
 
 
54
  std::pair<Map::iterator, bool> ret=
 
55
    cache.insert(std::make_pair(identifier.getKey(), share));
 
56
 
 
57
  return ret.second;
47
58
}
48
59
 
49
60
bool Cache::insert(const identifier::Table &identifier, drizzled::message::Table &message)
50
61
{
51
 
  return insert(identifier, table::shared_ptr(new message::Table(message)));
 
62
  boost_unique_lock_t scoped_lock(_access);
 
63
 
 
64
  table::shared_ptr share;
 
65
  share.reset(new message::Table(message));
 
66
 
 
67
  std::pair<Map::iterator, bool> ret=
 
68
    cache.insert(std::make_pair(identifier.getKey(), share));
 
69
 
 
70
  return ret.second;
52
71
}
53
72
 
54
 
} // namespace message
55
 
} // namespace drizzled
 
73
} /* namespace definition */
 
74
} /* namespace drizzled */