From c7e1c4bfdb26dd51714c95bc7131ad949965482a Mon Sep 17 00:00:00 2001 From: Noah Watkins Date: Sun, 29 Dec 2013 10:32:22 -0800 Subject: [PATCH] c++11: fix std::lock naming conflicts Unfortunately, 'using namespace std;' is in pretty widespread use in the Ceph tree, so we need to rename to avoid the conflict. Example error output: test/streamtest.cc:37:19: error: reference to 'lock' is ambiguous Mutex::Locker l(lock); ^ test/streamtest.cc:32:7: note: candidate found by name lookup is 'lock' Mutex lock("streamtest.cc lock"); ^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/mutex:346:1: note: candidate found by name lookup is 'std::__1::lock' lock(_L0& __l0, _L1& __l1) Signed-off-by: Noah Watkins --- src/test/librados/tier.cc | 16 ++++++++-------- src/test/streamtest.cc | 12 ++++++------ src/test/test_filejournal.cc | 32 ++++++++++++++++---------------- src/test/testmsgr.cc | 12 ++++++------ 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/test/librados/tier.cc b/src/test/librados/tier.cc index 883234f0ee529..401b6ab11386a 100644 --- a/src/test/librados/tier.cc +++ b/src/test/librados/tier.cc @@ -1074,7 +1074,7 @@ TEST(LibRadosTier, FlushTryFlushRaces) { IoCtx *read_ioctx = 0; -Mutex lock("FlushReadRaces::lock"); +Mutex test_lock("FlushReadRaces::lock"); Cond cond; int max_reads = 100; int num_reads = 0; // in progress @@ -1095,7 +1095,7 @@ void start_flush_read() void flush_read_race_cb(completion_t cb, void *arg) { //cout << " finished read" << std::endl; - lock.Lock(); + test_lock.Lock(); if (num_reads > max_reads) { num_reads--; cond.Signal(); @@ -1103,7 +1103,7 @@ void flush_read_race_cb(completion_t cb, void *arg) start_flush_read(); } // fixme: i'm leaking cb... - lock.Unlock(); + test_lock.Unlock(); } TEST(LibRadosTier, TryFlushReadRace) { @@ -1149,12 +1149,12 @@ TEST(LibRadosTier, TryFlushReadRace) { // start a continuous stream of reads read_ioctx = &base_ioctx; - lock.Lock(); + test_lock.Lock(); for (int i = 0; i < max_reads; ++i) { start_flush_read(); num_reads++; } - lock.Unlock(); + test_lock.Unlock(); // try-flush ObjectWriteOperation op; @@ -1170,11 +1170,11 @@ TEST(LibRadosTier, TryFlushReadRace) { completion->release(); // stop reads - lock.Lock(); + test_lock.Lock(); max_reads = 0; while (num_reads > 0) - cond.Wait(lock); - lock.Unlock(); + cond.Wait(test_lock); + test_lock.Unlock(); // tear down tiers ASSERT_EQ(0, cluster.mon_command( diff --git a/src/test/streamtest.cc b/src/test/streamtest.cc index 21693ac8713c9..d4ccadf18e120 100644 --- a/src/test/streamtest.cc +++ b/src/test/streamtest.cc @@ -29,15 +29,15 @@ struct io { }; map writes; Cond cond; -Mutex lock("streamtest.cc lock"); +Mutex test_lock("streamtest.cc lock"); unsigned concurrent = 1; void throttle() { - Mutex::Locker l(lock); + Mutex::Locker l(test_lock); while (writes.size() >= concurrent) { //generic_dout(0) << "waiting" << dendl; - cond.Wait(lock); + cond.Wait(test_lock); } } @@ -60,13 +60,13 @@ void pr(off_t off) void set_start(off_t off, utime_t t) { - Mutex::Locker l(lock); + Mutex::Locker l(test_lock); writes[off].start = t; } void set_ack(off_t off, utime_t t) { - Mutex::Locker l(lock); + Mutex::Locker l(test_lock); //generic_dout(0) << "ack " << off << dendl; writes[off].ack = t; if (writes[off].done()) @@ -75,7 +75,7 @@ void set_ack(off_t off, utime_t t) void set_commit(off_t off, utime_t t) { - Mutex::Locker l(lock); + Mutex::Locker l(test_lock); //generic_dout(0) << "commit " << off << dendl; writes[off].commit = t; if (writes[off].done()) diff --git a/src/test/test_filejournal.cc b/src/test/test_filejournal.cc index 7365e97dec0a9..3691fa64f4bec 100644 --- a/src/test/test_filejournal.cc +++ b/src/test/test_filejournal.cc @@ -22,15 +22,15 @@ bool aio = false; // ---- Cond cond; -Mutex lock("lock"); +Mutex wait_lock("lock"); bool done; void wait() { - lock.Lock(); + wait_lock.Lock(); while (!done) - cond.Wait(lock); - lock.Unlock(); + cond.Wait(wait_lock); + wait_lock.Unlock(); } // ---- @@ -120,7 +120,7 @@ TEST(TestFileJournal, WriteSmall) { bufferlist bl; bl.append("small"); - j.submit_entry(1, bl, 0, new C_SafeCond(&lock, &cond, &done)); + j.submit_entry(1, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); wait(); j.close(); @@ -138,7 +138,7 @@ TEST(TestFileJournal, WriteBig) { memset(foo, 1, sizeof(foo)); bl.append(foo, sizeof(foo)); } - j.submit_entry(1, bl, 0, new C_SafeCond(&lock, &cond, &done)); + j.submit_entry(1, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); wait(); j.close(); @@ -150,7 +150,7 @@ TEST(TestFileJournal, WriteMany) { ASSERT_EQ(0, j.create()); j.make_writeable(); - C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&lock, &cond, &done)); + C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&wait_lock, &cond, &done)); bufferlist bl; bl.append("small"); @@ -173,7 +173,7 @@ TEST(TestFileJournal, WriteManyVecs) { ASSERT_EQ(0, j.create()); j.make_writeable(); - C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&lock, &cond, &done)); + C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&wait_lock, &cond, &done)); bufferlist first; first.append("small"); @@ -210,7 +210,7 @@ TEST(TestFileJournal, ReplaySmall) { ASSERT_EQ(0, j.create()); j.make_writeable(); - C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&lock, &cond, &done)); + C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&wait_lock, &cond, &done)); bufferlist bl; bl.append("small"); @@ -255,7 +255,7 @@ TEST(TestFileJournal, ReplayCorrupt) { ASSERT_EQ(0, j.create()); j.make_writeable(); - C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&lock, &cond, &done)); + C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&wait_lock, &cond, &done)); const char *needle = "i am a needle"; const char *newneedle = "in a haystack"; @@ -403,7 +403,7 @@ TEST(TestFileJournal, ReplayDetectCorruptFooterMagic) { ASSERT_EQ(0, j.create()); j.make_writeable(); - C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&lock, &cond, &done)); + C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&wait_lock, &cond, &done)); const char *needle = "i am a needle"; for (unsigned i = 1; i <= 4; ++i) { @@ -416,7 +416,7 @@ TEST(TestFileJournal, ReplayDetectCorruptFooterMagic) { bufferlist bl; bl.append("needle"); - j.submit_entry(5, bl, 0, new C_SafeCond(&lock, &cond, &done)); + j.submit_entry(5, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); wait(); j.close(); @@ -453,7 +453,7 @@ TEST(TestFileJournal, ReplayDetectCorruptPayload) { ASSERT_EQ(0, j.create()); j.make_writeable(); - C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&lock, &cond, &done)); + C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&wait_lock, &cond, &done)); const char *needle = "i am a needle"; for (unsigned i = 1; i <= 4; ++i) { @@ -466,7 +466,7 @@ TEST(TestFileJournal, ReplayDetectCorruptPayload) { bufferlist bl; bl.append("needle"); - j.submit_entry(5, bl, 0, new C_SafeCond(&lock, &cond, &done)); + j.submit_entry(5, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); wait(); j.close(); @@ -503,7 +503,7 @@ TEST(TestFileJournal, ReplayDetectCorruptHeader) { ASSERT_EQ(0, j.create()); j.make_writeable(); - C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&lock, &cond, &done)); + C_GatherBuilder gb(g_ceph_context, new C_SafeCond(&wait_lock, &cond, &done)); const char *needle = "i am a needle"; for (unsigned i = 1; i <= 4; ++i) { @@ -516,7 +516,7 @@ TEST(TestFileJournal, ReplayDetectCorruptHeader) { bufferlist bl; bl.append("needle"); - j.submit_entry(5, bl, 0, new C_SafeCond(&lock, &cond, &done)); + j.submit_entry(5, bl, 0, new C_SafeCond(&wait_lock, &cond, &done)); wait(); j.close(); diff --git a/src/test/testmsgr.cc b/src/test/testmsgr.cc index 4de779b5d7f0c..bcde69f8745c5 100644 --- a/src/test/testmsgr.cc +++ b/src/test/testmsgr.cc @@ -39,7 +39,7 @@ using namespace std; Messenger *messenger = 0; -Mutex lock("mylock"); +Mutex test_lock("mylock"); Cond cond; uint64_t received = 0; @@ -55,10 +55,10 @@ private: //cerr << "got ping from " << m->get_source() << std::endl; dout(0) << "got ping from " << m->get_source() << dendl; - lock.Lock(); + test_lock.Lock(); ++received; cond.Signal(); - lock.Unlock(); + test_lock.Unlock(); m->put(); return true; @@ -112,13 +112,13 @@ int main(int argc, const char **argv, const char *envp[]) { if (whoami == 0) isend = 100; - lock.Lock(); + test_lock.Lock(); uint64_t sent = 0; while (1) { while (received + isend <= sent) { //cerr << "wait r " << received << " s " << sent << " is " << isend << std::endl; dout(0) << "wait r " << received << " s " << sent << " is " << isend << dendl; - cond.Wait(lock); + cond.Wait(test_lock); } int t = rand() % mc.get_num_mon(); @@ -135,7 +135,7 @@ int main(int argc, const char **argv, const char *envp[]) { messenger->send_message(new MPing, mc.get_mon_inst(t)); cerr << isend << "\t" << ++sent << "\t" << received << "\r"; } - lock.Unlock(); + test_lock.Unlock(); // wait for messenger to finish rank->wait(); -- 2.39.5