Switch from the benighted PlatformThread to the shiny SimpleThread
Also add a comment to explain the strange tls gyrations in SlotReturnFunction. Review URL: http://codereview.chromium.org/8972 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4481 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -345,6 +345,9 @@ void StatsTable::UnregisterThread(StatsTableTLSData* data) {
|
||||
}
|
||||
|
||||
void StatsTable::SlotReturnFunction(void* data) {
|
||||
// This is called by the TLS destructor, which on some platforms has
|
||||
// already cleared the TLS info, so use the tls_data argument
|
||||
// rather than trying to fetch it ourselves.
|
||||
StatsTableTLSData* tls_data = static_cast<StatsTableTLSData*>(data);
|
||||
if (tls_data) {
|
||||
DCHECK(tls_data->table);
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "base/multiprocess_test.h"
|
||||
#include "base/platform_thread.h"
|
||||
#include "base/simple_thread.h"
|
||||
#include "base/stats_table.h"
|
||||
#include "base/stats_counters.h"
|
||||
#include "base/string_util.h"
|
||||
@ -66,14 +67,16 @@ const std::wstring kCounterMixed = L"CounterMixed";
|
||||
// The number of thread loops that we will do.
|
||||
const int kThreadLoops = 1000;
|
||||
|
||||
class StatsTableThread : public PlatformThread::Delegate {
|
||||
class StatsTableThread : public base::SimpleThread {
|
||||
public:
|
||||
void ThreadMain();
|
||||
PlatformThreadHandle thread_;
|
||||
StatsTableThread(std::string name, int id)
|
||||
: base::SimpleThread(name), id_(id) { }
|
||||
virtual void Run();
|
||||
private:
|
||||
int id_;
|
||||
};
|
||||
|
||||
void StatsTableThread::ThreadMain() {
|
||||
void StatsTableThread::Run() {
|
||||
// Each thread will open the shared memory and set counters
|
||||
// concurrently in a loop. We'll use some pauses to
|
||||
// mixup the thread scheduling.
|
||||
@ -110,21 +113,20 @@ TEST_F(StatsTableTest, MultipleThreads) {
|
||||
// Spin up a set of threads to go bang on the various counters.
|
||||
// After we join the threads, we'll make sure the counters
|
||||
// contain the values we expected.
|
||||
StatsTableThread threads[kMaxThreads];
|
||||
StatsTableThread* threads[kMaxThreads];
|
||||
|
||||
// Spawn the threads.
|
||||
for (int index = 0; index < kMaxThreads; index++) {
|
||||
threads[index].id_ = index;
|
||||
bool created =
|
||||
PlatformThread::Create(0, &threads[index], &threads[index].thread_);
|
||||
EXPECT_EQ(true, created);
|
||||
EXPECT_NE(static_cast<PlatformThreadHandle>(0), threads[index].thread_);
|
||||
threads[index] = new StatsTableThread("MultipleThreadsTest", index);
|
||||
threads[index]->Start();
|
||||
}
|
||||
|
||||
// Wait for the threads to finish.
|
||||
for (int index = 0; index < kMaxThreads; index++) {
|
||||
PlatformThread::Join(threads[index].thread_);
|
||||
threads[index]->Join();
|
||||
delete threads[index];
|
||||
}
|
||||
|
||||
StatsCounter zero_counter(kCounterZero);
|
||||
StatsCounter lucky13_counter(kCounter1313);
|
||||
StatsCounter increment_counter(kCounterIncrement);
|
||||
|
Reference in New Issue
Block a user