Skip to content

Commit

Permalink
libc++: use ceph:: namespaced data types
Browse files Browse the repository at this point in the history
Switches the implemetnation of smart pointers and unordered map/set to
use the ceph:: versions.

Signed-off-by: Noah Watkins <[email protected]>
  • Loading branch information
dotnwat committed Jan 18, 2014
1 parent 8e86720 commit 4c4e1d0
Show file tree
Hide file tree
Showing 99 changed files with 446 additions and 451 deletions.
10 changes: 5 additions & 5 deletions fusetrace/fusetrace_ll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
#include <time.h>


#include <ext/hash_map>
using namespace __gnu_cxx;
#include "include/unordered_map.h"
#include "include/hash_namespace.h"

#ifndef __LP64__
namespace __gnu_cxx {
CEPH_HASH_NAMESPACE_START
template<> struct hash<uint64_t> {
size_t operator()(uint64_t __x) const {
static hash<uint32_t> H;
return H((__x >> 32) ^ (__x & 0xffffffff));
}
};
}
CEPH_HASH_NAMESPACE_END
#endif


Expand Down Expand Up @@ -89,7 +89,7 @@ struct Inode {
};

Inode *root = 0;
hash_map<ino_t, Inode*> inode_map;
ceph::unordered_map<ino_t, Inode*> inode_map;

bool make_inode_path(string &buf, Inode *in)
{
Expand Down
20 changes: 10 additions & 10 deletions src/client/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Client::~Client()
void Client::tear_down_cache()
{
// fd's
for (hash_map<int, Fh*>::iterator it = fd_map.begin();
for (ceph::unordered_map<int, Fh*>::iterator it = fd_map.begin();
it != fd_map.end();
++it) {
Fh *fh = it->second;
Expand Down Expand Up @@ -286,7 +286,7 @@ void Client::dump_inode(Formatter *f, Inode *in, set<Inode*>& did, bool disconne
did.insert(in);
if (in->dir) {
ldout(cct, 1) << " dir " << in->dir << " size " << in->dir->dentries.size() << dendl;
for (hash_map<string, Dentry*>::iterator it = in->dir->dentries.begin();
for (ceph::unordered_map<string, Dentry*>::iterator it = in->dir->dentries.begin();
it != in->dir->dentries.end();
++it) {
ldout(cct, 1) << " " << in->ino << " dn " << it->first << " " << it->second << " ref " << it->second->ref << dendl;
Expand Down Expand Up @@ -314,7 +314,7 @@ void Client::dump_cache(Formatter *f)
dump_inode(f, root, did, true);

// make a second pass to catch anything disconnected
for (hash_map<vinodeno_t, Inode*>::iterator it = inode_map.begin();
for (ceph::unordered_map<vinodeno_t, Inode*>::iterator it = inode_map.begin();
it != inode_map.end();
++it) {
if (did.count(it->second))
Expand Down Expand Up @@ -1184,7 +1184,7 @@ int Client::verify_reply_trace(int r,
bufferlist extra_bl;
inodeno_t created_ino;
bool got_created_ino = false;
hash_map<vinodeno_t, Inode*>::iterator p;
ceph::unordered_map<vinodeno_t, Inode*>::iterator p;

extra_bl.claim(reply->get_extra_bl());
if (extra_bl.length() >= 8) {
Expand Down Expand Up @@ -1958,8 +1958,8 @@ void Client::send_reconnect(MetaSession *session)
MClientReconnect *m = new MClientReconnect;

// i have an open session.
hash_set<inodeno_t> did_snaprealm;
for (hash_map<vinodeno_t, Inode*>::iterator p = inode_map.begin();
ceph::unordered_set<inodeno_t> did_snaprealm;
for (ceph::unordered_map<vinodeno_t, Inode*>::iterator p = inode_map.begin();
p != inode_map.end();
++p) {
Inode *in = p->second;
Expand Down Expand Up @@ -3859,8 +3859,8 @@ void Client::unmount()

if (cct->_conf->client_oc) {
// flush/release all buffered data
hash_map<vinodeno_t, Inode*>::iterator next;
for (hash_map<vinodeno_t, Inode*>::iterator p = inode_map.begin();
ceph::unordered_map<vinodeno_t, Inode*>::iterator next;
for (ceph::unordered_map<vinodeno_t, Inode*>::iterator p = inode_map.begin();
p != inode_map.end();
p = next) {
next = p;
Expand Down Expand Up @@ -6655,8 +6655,8 @@ int Client::_ll_put(Inode *in, int num)
void Client::_ll_drop_pins()
{
ldout(cct, 10) << "_ll_drop_pins" << dendl;
hash_map<vinodeno_t, Inode*>::iterator next;
for (hash_map<vinodeno_t, Inode*>::iterator it = inode_map.begin();
ceph::unordered_map<vinodeno_t, Inode*>::iterator next;
for (ceph::unordered_map<vinodeno_t, Inode*>::iterator it = inode_map.begin();
it != inode_map.end();
it = next) {
Inode *in = it->second;
Expand Down
11 changes: 5 additions & 6 deletions src/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ using std::set;
using std::map;
using std::fstream;

#include <ext/hash_map>
using namespace __gnu_cxx;
#include "include/unordered_map.h"

#include "include/filepath.h"
#include "include/interval_set.h"
Expand Down Expand Up @@ -302,14 +301,14 @@ class Client : public Dispatcher {
WritebackHandler *writeback_handler;

// cache
hash_map<vinodeno_t, Inode*> inode_map;
ceph::unordered_map<vinodeno_t, Inode*> inode_map;
Inode* root;
LRU lru; // lru list of Dentry's in our local metadata cache.

// all inodes with caps sit on either cap_list or delayed_caps.
xlist<Inode*> delayed_caps, cap_list;
int num_flushing_caps;
hash_map<inodeno_t,SnapRealm*> snap_realms;
ceph::unordered_map<inodeno_t,SnapRealm*> snap_realms;

SnapRealm *get_snap_realm(inodeno_t r);
SnapRealm *get_snap_realm_maybe(inodeno_t r);
Expand All @@ -324,7 +323,7 @@ class Client : public Dispatcher {

// file handles, etc.
interval_set<int> free_fd_set; // unused fds
hash_map<int, Fh*> fd_map;
ceph::unordered_map<int, Fh*> fd_map;

int get_fd() {
int fd = free_fd_set.range_start();
Expand All @@ -339,7 +338,7 @@ class Client : public Dispatcher {
* Resolve file descriptor, or return NULL.
*/
Fh *get_filehandle(int fd) {
hash_map<int, Fh*>::iterator p = fd_map.find(fd);
ceph::unordered_map<int, Fh*>::iterator p = fd_map.find(fd);
if (p == fd_map.end())
return NULL;
return p->second;
Expand Down
2 changes: 1 addition & 1 deletion src/client/Dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Inode;
class Dir {
public:
Inode *parent_inode; // my inode
hash_map<string, Dentry*> dentries;
ceph::unordered_map<string, Dentry*> dentries;
map<string, Dentry*> dentry_map;
uint64_t release_count;
uint64_t max_offset;
Expand Down
24 changes: 12 additions & 12 deletions src/client/SyntheticClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1014,12 +1014,12 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)

utime_t start = ceph_clock_now(client->cct);

hash_map<int64_t, int64_t> open_files;
hash_map<int64_t, dir_result_t*> open_dirs;
ceph::unordered_map<int64_t, int64_t> open_files;
ceph::unordered_map<int64_t, dir_result_t*> open_dirs;

hash_map<int64_t, Fh*> ll_files;
hash_map<int64_t, void*> ll_dirs;
hash_map<uint64_t, int64_t> ll_inos;
ceph::unordered_map<int64_t, Fh*> ll_files;
ceph::unordered_map<int64_t, void*> ll_dirs;
ceph::unordered_map<uint64_t, int64_t> ll_inos;

ll_inos[1] = 1; // root inode is known.

Expand Down Expand Up @@ -1479,25 +1479,25 @@ int SyntheticClient::play_trace(Trace& t, string& prefix, bool metadata_only)
lock.Unlock();

// close open files
for (hash_map<int64_t, int64_t>::iterator fi = open_files.begin();
for (ceph::unordered_map<int64_t, int64_t>::iterator fi = open_files.begin();
fi != open_files.end();
++fi) {
dout(1) << "leftover close " << fi->second << dendl;
if (fi->second > 0) client->close(fi->second);
}
for (hash_map<int64_t, dir_result_t*>::iterator fi = open_dirs.begin();
for (ceph::unordered_map<int64_t, dir_result_t*>::iterator fi = open_dirs.begin();
fi != open_dirs.end();
++fi) {
dout(1) << "leftover closedir " << fi->second << dendl;
if (fi->second != 0) client->closedir(fi->second);
}
for (hash_map<int64_t,Fh*>::iterator fi = ll_files.begin();
for (ceph::unordered_map<int64_t,Fh*>::iterator fi = ll_files.begin();
fi != ll_files.end();
++fi) {
dout(1) << "leftover ll_release " << fi->second << dendl;
if (fi->second) client->ll_release(fi->second);
}
for (hash_map<int64_t,void*>::iterator fi = ll_dirs.begin();
for (ceph::unordered_map<int64_t,void*>::iterator fi = ll_dirs.begin();
fi != ll_dirs.end();
++fi) {
dout(1) << "leftover ll_releasedir " << fi->second << dendl;
Expand Down Expand Up @@ -1559,8 +1559,8 @@ int SyntheticClient::full_walk(string& basedir)
memset(&empty, 0, sizeof(empty));
statq.push_back(empty);

hash_map<inodeno_t, int> nlink;
hash_map<inodeno_t, int> nlink_seen;
ceph::unordered_map<inodeno_t, int> nlink;
ceph::unordered_map<inodeno_t, int> nlink_seen;

while (!dirq.empty()) {
string dir = dirq.front();
Expand Down Expand Up @@ -1638,7 +1638,7 @@ int SyntheticClient::full_walk(string& basedir)
}
}

for (hash_map<inodeno_t,int>::iterator p = nlink.begin(); p != nlink.end(); ++p) {
for (ceph::unordered_map<inodeno_t,int>::iterator p = nlink.begin(); p != nlink.end(); ++p) {
if (nlink_seen[p->first] != p->second)
dout(0) << p->first << " nlink " << p->second << " != " << nlink_seen[p->first] << "seen" << dendl;
}
Expand Down
1 change: 0 additions & 1 deletion src/client/Trace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include <iostream>
#include <map>
using namespace __gnu_cxx;

#include "common/Mutex.h"

Expand Down
4 changes: 2 additions & 2 deletions src/client/fuse_ll.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ class CephFuse::Handle {

Mutex stag_lock;
int last_stag;
hash_map<uint64_t,int> snap_stag_map;
hash_map<int,uint64_t> stag_snap_map;
ceph::unordered_map<uint64_t,int> snap_stag_map;
ceph::unordered_map<int,uint64_t> stag_snap_map;

};

Expand Down
4 changes: 2 additions & 2 deletions src/common/TrackedOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include "include/histogram.h"
#include "include/xlist.h"
#include "msg/Message.h"
#include <tr1/memory>
#include "include/memory.h"

class TrackedOp;
typedef std::tr1::shared_ptr<TrackedOp> TrackedOpRef;
typedef ceph::shared_ptr<TrackedOp> TrackedOpRef;

class OpTracker;
class OpHistory {
Expand Down
10 changes: 5 additions & 5 deletions src/common/hobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ struct hobject_t {
/* Do not use when a particular hash function is needed */
explicit hobject_t(const sobject_t &o) :
oid(o.oid), snap(o.snap), max(false), pool(-1) {
hash = __gnu_cxx::hash<sobject_t>()(o);
hash = CEPH_HASH_NAMESPACE::hash<sobject_t>()(o);
}

// maximum sorted value.
Expand Down Expand Up @@ -198,15 +198,15 @@ struct hobject_t {
};
WRITE_CLASS_ENCODER(hobject_t)

namespace __gnu_cxx {
CEPH_HASH_NAMESPACE_START
template<> struct hash<hobject_t> {
size_t operator()(const hobject_t &r) const {
static hash<object_t> H;
static rjhash<uint64_t> I;
return H(r.oid) ^ I(r.snap);
}
};
}
CEPH_HASH_NAMESPACE_END

ostream& operator<<(ostream& out, const hobject_t& o);

Expand Down Expand Up @@ -297,15 +297,15 @@ struct ghobject_t {
};
WRITE_CLASS_ENCODER(ghobject_t)

namespace __gnu_cxx {
CEPH_HASH_NAMESPACE_START
template<> struct hash<ghobject_t> {
size_t operator()(const ghobject_t &r) const {
static hash<object_t> H;
static rjhash<uint64_t> I;
return H(r.hobj.oid) ^ I(r.hobj.snap);
}
};
}
CEPH_HASH_NAMESPACE_END

ostream& operator<<(ostream& out, const ghobject_t& o);

Expand Down
15 changes: 8 additions & 7 deletions src/common/lockdep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
#include "include/types.h"
#include "lockdep.h"

#include <ext/hash_map>
#include "include/unordered_map.h"
#include "include/hash_namespace.h"

#if defined(__FreeBSD__) && defined(__LP64__) // On FreeBSD pthread_t is a pointer.
namespace __gnu_cxx {
CEPH_HASH_NAMESPACE_START
template<>
struct hash<pthread_t>
{
size_t
operator()(pthread_t __x) const
{ return (uintptr_t)__x; }
};
}
CEPH_HASH_NAMESPACE_END
#endif

/******* Constants **********/
Expand All @@ -50,10 +51,10 @@ struct lockdep_stopper_t {
static pthread_mutex_t lockdep_mutex = PTHREAD_MUTEX_INITIALIZER;
static CephContext *g_lockdep_ceph_ctx = NULL;
static lockdep_stopper_t lockdep_stopper;
static hash_map<const char *, int> lock_ids;
static ceph::unordered_map<const char *, int> lock_ids;
static map<int, const char *> lock_names;
static int last_id = 0;
static hash_map<pthread_t, map<int,BackTrace*> > held;
static ceph::unordered_map<pthread_t, map<int,BackTrace*> > held;
static BackTrace *follows[MAX_LOCKS][MAX_LOCKS]; // follows[a][b] means b taken after a

/******* Functions **********/
Expand All @@ -79,7 +80,7 @@ int lockdep_dump_locks()
{
pthread_mutex_lock(&lockdep_mutex);

for (hash_map<pthread_t, map<int,BackTrace*> >::iterator p = held.begin();
for (ceph::unordered_map<pthread_t, map<int,BackTrace*> >::iterator p = held.begin();
p != held.end();
++p) {
lockdep_dout(0) << "--- thread " << p->first << " ---" << dendl;
Expand Down Expand Up @@ -109,7 +110,7 @@ int lockdep_register(const char *name)
for (int j=0; j<MAX_LOCKS; j++)
follows[i][j] = NULL;

hash_map<const char *, int>::iterator p = lock_ids.find(name);
ceph::unordered_map<const char *, int>::iterator p = lock_ids.find(name);
if (p == lock_ids.end()) {
assert(last_id < MAX_LOCKS);
id = last_id++;
Expand Down
2 changes: 1 addition & 1 deletion src/common/map_cacher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <boost/scoped_ptr.hpp>
#include <boost/optional.hpp>
#include <tr1/memory>
#include "include/memory.h"
#include <set>
#include <map>
#include <utility>
Expand Down
4 changes: 2 additions & 2 deletions src/common/shared_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

template <class K, class V>
class SharedLRU {
typedef std::tr1::shared_ptr<V> VPtr;
typedef std::tr1::weak_ptr<V> WeakVPtr;
typedef ceph::shared_ptr<V> VPtr;
typedef ceph::weak_ptr<V> WeakVPtr;
Mutex lock;
size_t max_size;
Cond cond;
Expand Down
4 changes: 2 additions & 2 deletions src/common/sharedptr_registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
template <class K, class V>
class SharedPtrRegistry {
public:
typedef std::tr1::shared_ptr<V> VPtr;
typedef std::tr1::weak_ptr<V> WeakVPtr;
typedef ceph::shared_ptr<V> VPtr;
typedef ceph::weak_ptr<V> WeakVPtr;
int waiting;
private:
Mutex lock;
Expand Down
Loading

0 comments on commit 4c4e1d0

Please sign in to comment.