~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/cache.cc

Merge Revision revid:marko.makela@oracle.com-20100601140355-u3kxl0yl0ljl5tx9 from MySQL InnoDB

Original revid:marko.makela@oracle.com-20100601140355-u3kxl0yl0ljl5tx9

Original Authors: Marko Mäkelä <marko.makela@oracle.com>
Original commit message:
Merge a change from mysql-5.1-innodb:

  ------------------------------------------------------------
  revno: 3491
  revision-id: marko.makela@oracle.com-20100601134335-ccthwwru23kn09qw
  parent: marko.makela@oracle.com-20100601120751-1uq7bbta5n7ts0qr
  committer: Marko Mäkelä <marko.makela@oracle.com>
  branch nick: 5.1-innodb
  timestamp: Tue 2010-06-01 16:43:35 +0300
  message:
    Bug#48197: Concurrent rw_lock_free may cause assertion failure

    rw_lock_t: Remove magic_n unless UNIV_DEBUG is defined.
    rw_lock_free(): Invalidate magic_n only after removing from rw_lock_list.

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>
22
 
 
23
 
#include <boost/bind.hpp>
24
 
#include <boost/thread/mutex.hpp>
25
 
#include <boost/thread/shared_mutex.hpp>
26
 
 
27
 
#include <drizzled/session.h>
28
 
#include <drizzled/identifier/table.h>
29
 
#include <drizzled/definition/cache.h>
30
 
 
31
 
#include <drizzled/table/instance.h>
 
21
#include "config.h"
 
22
 
 
23
#include "drizzled/pthread_globals.h"
 
24
#include "drizzled/session.h"
 
25
#include "drizzled/identifier/table.h"
 
26
#include "drizzled/definition/table.h"
32
27
 
33
28
namespace drizzled {
34
29
 
35
30
namespace definition {
36
31
 
37
 
table::instance::Shared::shared_ptr Cache::find(const identifier::Table::Key &key)
 
32
TableSharePtr Cache::find(const TableIdentifier &identifier)
38
33
{
39
 
  boost::mutex::scoped_lock scopedLock(_mutex);
 
34
  //safe_mutex_assert_owner(LOCK_open.native_handle);
40
35
 
41
 
  Map::iterator iter= cache.find(key);
 
36
  CacheMap::iterator iter= cache.find(identifier.getKey());
42
37
  if (iter != cache.end())
43
38
  {
44
39
    return (*iter).second;
45
40
  }
46
41
 
47
 
  return table::instance::Shared::shared_ptr();
 
42
  return TableSharePtr();
48
43
}
49
44
 
50
 
void Cache::erase(const identifier::Table::Key &key)
 
45
void Cache::erase(const TableIdentifier &identifier)
51
46
{
52
 
  boost::mutex::scoped_lock scopedLock(_mutex);
 
47
  //safe_mutex_assert_owner(LOCK_open.native_handle);
53
48
  
54
 
  cache.erase(key);
 
49
  cache.erase(identifier.getKey());
55
50
}
56
51
 
57
 
bool Cache::insert(const identifier::Table::Key &key, table::instance::Shared::shared_ptr share)
 
52
bool Cache::insert(const TableIdentifier &identifier, TableSharePtr share)
58
53
{
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));
62
56
 
63
57
  return ret.second;
64
58
}
65
59
 
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
 
 
79
60
} /* namespace definition */
80
61
} /* namespace drizzled */