Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1385)

Unified Diff: base/threading/thread_local_storage_unittest.cc

Issue 8702014: Make ThreadLocalStorage more posix pthread compliant (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/threading/thread_local_storage_unittest.cc
===================================================================
--- base/threading/thread_local_storage_unittest.cc (revision 111452)
+++ base/threading/thread_local_storage_unittest.cc (working copy)
@@ -22,6 +22,10 @@
namespace {
const int kInitialTlsValue = 0x5555;
+const int kFinalTlsValue = 0x7777;
+// How many times must a destructor be called before we really are done.
+const int kNumberDestructorCallRepetitions = 8;
+
static ThreadLocalStorage::Slot tls_slot(LINKER_INITIALIZED);
class ThreadLocalStorageRunner : public DelegateSimpleThread::Delegate {
@@ -43,6 +47,8 @@
ptr = static_cast<int*>(tls_slot.Get());
EXPECT_EQ(ptr, tls_value_ptr_);
EXPECT_EQ(*ptr, 0);
+
+ *ptr = kFinalTlsValue + kNumberDestructorCallRepetitions;
}
private:
@@ -53,8 +59,15 @@
void ThreadLocalStorageCleanup(void *value) {
int *ptr = reinterpret_cast<int*>(value);
- if (ptr)
- *ptr = kInitialTlsValue;
+ // Destructors should never be called wit a NULL.
willchan no longer on Chromium 2011/11/29 01:46:49 s/wit/with/
jar (doing other things) 2011/11/29 02:32:45 Done.
+ ASSERT_NE(ptr, reinterpret_cast<int*>(NULL));
willchan no longer on Chromium 2011/11/29 01:46:49 Should be ASSERT_OP(expected, actual). You have it
jar (doing other things) 2011/11/29 02:32:45 Done.
+ if (*ptr == kFinalTlsValue)
+ return; // We've been called enough times.
+ ASSERT_GT(*ptr, kFinalTlsValue);
+ ASSERT_LE(*ptr, kFinalTlsValue + kNumberDestructorCallRepetitions);
+ --*ptr; // Move closer to our target.
+ // Tell tls that we're not done with this thread, and still need destruction.
+ tls_slot.Set(value);
}
} // namespace
@@ -93,7 +106,7 @@
delete thread_delegates[index];
// Verify that the destructor was called and that we reset.
- EXPECT_EQ(values[index], kInitialTlsValue);
+ EXPECT_EQ(values[index], kFinalTlsValue);
willchan no longer on Chromium 2011/11/29 01:46:49 Looks like this one was wrong too, can you fix the
jar (doing other things) 2011/11/29 02:32:45 Done.
}
tls_slot.Free(); // Stop doing callbacks to cleanup threads.
}

Powered by Google App Engine
This is Rietveld 408576698