class SharedLRUTest : public SharedLRU<unsigned int, int> {
public:
- Mutex &get_lock() { return lock; }
- Cond &get_cond() { return cond; }
- map<unsigned int, pair< ceph::weak_ptr<int>, int* > > &get_weak_refs() {
+ auto& get_lock() { return lock; }
+ auto& get_cond() { return cond; }
+ map<unsigned int, pair< std::weak_ptr<int>, int* > > &get_weak_refs() {
return weak_refs;
}
};
SharedLRUTest &cache;
unsigned int key;
int value;
- ceph::shared_ptr<int> ptr;
+ std::shared_ptr<int> ptr;
enum in_method_t { LOOKUP, LOWER_BOUND } in_method;
Thread_wait(SharedLRUTest& _cache, unsigned int _key,
ptr = cache.lower_bound(key);
break;
case LOOKUP:
- ptr = ceph::shared_ptr<int>(new int);
+ ptr = std::shared_ptr<int>(new int);
*ptr = value;
ptr = cache.lookup(key);
break;
if (delay > 0)
usleep(delay);
{
- Mutex::Locker l(cache.get_lock());
+ std::lock_guard l{cache.get_lock()};
if (cache.waiting == waitting) {
break;
}
int value1 = 2;
bool existed = false;
{
- ceph::shared_ptr<int> ptr = cache.add(key, new int(value1), &existed);
+ std::shared_ptr<int> ptr = cache.add(key, new int(value1), &existed);
ASSERT_EQ(value1, *ptr);
ASSERT_FALSE(existed);
}
{
int value2 = 3;
- ceph::shared_ptr<int> ptr = cache.add(key, new int(value2), &existed);
+ auto p = new int(value2);
+ std::shared_ptr<int> ptr = cache.add(key, p, &existed);
ASSERT_EQ(value1, *ptr);
ASSERT_TRUE(existed);
+ delete p;
}
}
TEST_F(SharedLRU_all, empty) {
ASSERT_TRUE(cache.empty());
{
int value1 = 2;
- ceph::shared_ptr<int> ptr = cache.add(key, new int(value1), &existed);
+ std::shared_ptr<int> ptr = cache.add(key, new int(value1), &existed);
ASSERT_EQ(value1, *ptr);
ASSERT_FALSE(existed);
}
int value = 2;
{
- ceph::shared_ptr<int> ptr(new int);
+ std::shared_ptr<int> ptr(new int);
cache.get_weak_refs()[key] = make_pair(ptr, &*ptr);
}
EXPECT_FALSE(cache.get_weak_refs()[key].first.lock());
// waiting on a key does not block lookups on other keys
EXPECT_FALSE(cache.lookup(key + 12345));
{
- Mutex::Locker l(cache.get_lock());
+ std::lock_guard l{cache.get_lock()};
cache.get_weak_refs().erase(key);
- cache.get_cond().Signal();
+ cache.get_cond().notify_one();
}
ASSERT_TRUE(wait_for(cache, 0));
t.join();
int value = 2;
{
- ceph::shared_ptr<int> ptr(new int);
+ std::shared_ptr<int> ptr(new int);
cache.get_weak_refs()[key] = make_pair(ptr, &*ptr);
}
EXPECT_FALSE(cache.get_weak_refs()[key].first.lock());
// waiting on a key does not block lookups on other keys
EXPECT_TRUE(cache.lookup_or_create(key + 12345).get());
{
- Mutex::Locker l(cache.get_lock());
+ std::lock_guard l{cache.get_lock()};
cache.get_weak_refs().erase(key);
- cache.get_cond().Signal();
+ cache.get_cond().notify_one();
}
ASSERT_TRUE(wait_for(cache, 0));
t.join();
ASSERT_TRUE(cache.add(other_key, new int(other_value)).get());
{
- ceph::shared_ptr<int> ptr(new int);
+ std::shared_ptr<int> ptr(new int);
cache.get_weak_refs()[key] = make_pair(ptr, &*ptr);
}
EXPECT_FALSE(cache.get_weak_refs()[key].first.lock());
// waiting on a key does not block getting lower_bound on other keys
EXPECT_TRUE(cache.lower_bound(other_key).get());
{
- Mutex::Locker l(cache.get_lock());
+ std::lock_guard l{cache.get_lock()};
cache.get_weak_refs().erase(key);
- cache.get_cond().Signal();
+ cache.get_cond().notify_one();
}
ASSERT_TRUE(wait_for(cache, 0));
t.join();
SharedLRUTest cache;
const unsigned int key2 = 333;
- ceph::shared_ptr<int> ptr2 = cache.lookup_or_create(key2);
+ std::shared_ptr<int> ptr2 = cache.lookup_or_create(key2);
const int value2 = *ptr2 = 400;
// entries with expired pointers are silently ignored
const unsigned int key_gone = 222;
- cache.get_weak_refs()[key_gone] = make_pair(ceph::shared_ptr<int>(), (int*)0);
+ cache.get_weak_refs()[key_gone] = make_pair(std::shared_ptr<int>(), (int*)0);
const unsigned int key1 = 111;
- ceph::shared_ptr<int> ptr1 = cache.lookup_or_create(key1);
+ std::shared_ptr<int> ptr1 = cache.lookup_or_create(key1);
const int value1 = *ptr1 = 800;
pair<unsigned int, int> i;
{
SharedLRUTest cache;
const unsigned int key1 = 111;
- ceph::shared_ptr<int> *ptr1 = new shared_ptr<int>(cache.lookup_or_create(key1));
+ std::shared_ptr<int> *ptr1 = new shared_ptr<int>(cache.lookup_or_create(key1));
const unsigned int key2 = 222;
- ceph::shared_ptr<int> ptr2 = cache.lookup_or_create(key2);
+ std::shared_ptr<int> ptr2 = cache.lookup_or_create(key2);
- pair<unsigned int, ceph::shared_ptr<int> > i;
+ pair<unsigned int, std::shared_ptr<int> > i;
EXPECT_TRUE(cache.get_next(i.first, &i));
EXPECT_EQ(key1, i.first);
delete ptr1;
unsigned int key = 1;
int value = 2;
{
- ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
+ std::shared_ptr<int> ptr = cache.add(key, new int(value));
ASSERT_EQ(value, *cache.lookup(key));
}
ASSERT_TRUE(cache.lookup(key).get());
ASSERT_FALSE(cache.lookup(key));
{
- ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
+ std::shared_ptr<int> ptr = cache.add(key, new int(value));
}
ASSERT_TRUE(cache.lookup(key).get());
cache.clear(key);
unsigned int key = 1;
int value = 2;
{
- ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
+ std::shared_ptr<int> ptr = cache.add(key, new int(value));
ASSERT_EQ(value, *cache.lookup(key));
}
ASSERT_TRUE(cache.lookup(key).get());
cache.clear();
ASSERT_FALSE(cache.lookup(key));
- ceph::shared_ptr<int> ptr2 = cache.add(key, new int(value));
+ std::shared_ptr<int> ptr2 = cache.add(key, new int(value));
ASSERT_TRUE(cache.lookup(key).get());
cache.clear();
ASSERT_TRUE(cache.lookup(key).get());
SharedLRU<int, int> cache;
unsigned int key = 1;
int value = 2;
- ceph::shared_ptr<int> ptr = cache.add(key, new int(value));
+ std::shared_ptr<int> ptr = cache.add(key, new int(value));
ASSERT_EQ(ptr, cache.lookup(key));
ASSERT_EQ(value, *cache.lookup(key));
}
SharedLRU<int, int> cache(NULL, SIZE);
bool existed = false;
- ceph::shared_ptr<int> ptr = cache.add(0, new int(0), &existed);
+ std::shared_ptr<int> ptr = cache.add(0, new int(0), &existed);
ASSERT_FALSE(existed);
{
int *tmpint = new int(0);
- ceph::shared_ptr<int> ptr2 = cache.add(0, tmpint, &existed);
+ std::shared_ptr<int> ptr2 = cache.add(0, tmpint, &existed);
ASSERT_TRUE(existed);
delete tmpint;
}
cache.purge(0);
ASSERT_FALSE(cache.lookup(0));
- ceph::shared_ptr<int> ptr2 = cache.add(0, new int(0), &existed);
+ std::shared_ptr<int> ptr2 = cache.add(0, new int(0), &existed);
ASSERT_FALSE(ptr == ptr2);
- ptr = ceph::shared_ptr<int>();
+ ptr = std::shared_ptr<int>();
ASSERT_TRUE(cache.lookup(0).get());
}