mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
use CAS when returning SuperVersion to ThreadLocal
Summary: Add a check at the end of GetImpl to release SuperVersion if it becomes obsolete. Also do Scrape() inside InstallSuperVersion so it happens more frequent. Test Plan: make all check running asan_check now Reviewers: igor, haobo, sdong, dhruba Reviewed By: haobo CC: leveldb Differential Revision: https://reviews.facebook.net/D16641
This commit is contained in:
@@ -435,8 +435,8 @@ TEST(ThreadLocalTest, Scrape) {
|
||||
// Scrape all thread local data. No unref at thread
|
||||
// exit or ThreadLocalPtr destruction
|
||||
autovector<void*> ptrs;
|
||||
p.tls1.Scrape(&ptrs);
|
||||
p.tls2->Scrape(&ptrs);
|
||||
p.tls1.Scrape(&ptrs, nullptr);
|
||||
p.tls2->Scrape(&ptrs, nullptr);
|
||||
delete p.tls2;
|
||||
// Signal to exit
|
||||
mu.Lock();
|
||||
@@ -449,6 +449,22 @@ TEST(ThreadLocalTest, Scrape) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ThreadLocalTest, CompareAndSwap) {
|
||||
ThreadLocalPtr tls;
|
||||
ASSERT_TRUE(tls.Swap(reinterpret_cast<void*>(1)) == nullptr);
|
||||
void* expected = reinterpret_cast<void*>(1);
|
||||
// Swap in 2
|
||||
ASSERT_TRUE(tls.CompareAndSwap(reinterpret_cast<void*>(2), expected));
|
||||
expected = reinterpret_cast<void*>(100);
|
||||
// Fail Swap, still 2
|
||||
ASSERT_TRUE(!tls.CompareAndSwap(reinterpret_cast<void*>(2), expected));
|
||||
ASSERT_EQ(expected, reinterpret_cast<void*>(2));
|
||||
// Swap in 3
|
||||
expected = reinterpret_cast<void*>(2);
|
||||
ASSERT_TRUE(tls.CompareAndSwap(reinterpret_cast<void*>(3), expected));
|
||||
ASSERT_EQ(tls.Get(), reinterpret_cast<void*>(3));
|
||||
}
|
||||
|
||||
} // namespace rocksdb
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
Reference in New Issue
Block a user